Convert HTML (tinyMCE) to WORD (.docx)

I was able to successfully create the .docx document from https://github.com/djpate/docxgen , but as soon as I try to include the TinyMCE text, I can no longer open the document. (invalid char).

Is there a way to convert HTML text before giving it to docxgen to avoid such an error?

+4
source share
3 answers

I decided to go with the pro version of the library http://www.phpdocx.com/ , as it simplifies the whole process. Hope it will fill my needs.

+3
source

Finally, I decided with this answer to create a doc (just output html and Word recognizes it):

  header( 'Content-Type: application/msword' ); header("Content-disposition: attachment; filename=" .date("Ymd").".doc"); /* header("Content-type: application/vnd.ms-word"); header("Content-disposition: attachment; filename=" .date("Ymd").".rtf"); */ $html = preg_replace('%/[^\\s]+\\.(jpg|jpeg|png|gif)%i', 'http://www.akubocrm.com\\0', $html); print "<html xmlns:v=\"urn:schemas-microsoft-com:vml\""; print "xmlns:o=\"urn:schemas-microsoft-com:office:office\""; print "xmlns:w=\"urn:schemas-microsoft-com:office:word\""; print "xmlns=\"http://www.w3.org/TR/REC-html40\">"; print "<xml> <w:WordDocument> <w:View>Print</w:View> <w:DoNotHyphenateCaps/> <w:PunctuationKerning/> <w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing> <w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing> </w:WordDocument> </xml> "; die($html); 
+6
source

Another solution uses http://htmltodocx.codeplex.com/ , which has just been released.

However, I tried this and it ruined my invoice (if I used tables that I shouldn't have)

Jim

0
source

Source: https://habr.com/ru/post/1397773/


All Articles