Convert HTML (tinyMCE) to WORD (.docx)
14,190
Solution 1
I've decided to go with the pro version of the library http://www.phpdocx.com/ as it simplifies the whole process. I hope it'll fill my needs.
Solution 2
Finally, I settled with this answer to create a doc (simply output html and Word will recognize it):
header( 'Content-Type: application/msword' );
header("Content-disposition: attachment; filename=" .date("Y-m-d").".doc");
/*
header("Content-type: application/vnd.ms-word");
header("Content-disposition: attachment; filename=" .date("Y-m-d").".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);
Author by
sf_tristanb
CTO @ Y-Proximité (Lyon - France) | @sf_tristanb Symfony developper | Personal project : http://www.seek-team.com
Updated on June 11, 2022Comments
-
sf_tristanb almost 2 years
I've been successfully able to generate a
.docx
document with https://github.com/djpate/docxgen but as soon as i try to include TinyMCE text, i no longer can open the document. (non valid char).Is there a way to convert the HTML text before giving it to docxgen to avoid such error?
-
ZanattMan over 11 yearsThis software is privative and you have to pay to use almost every useful function, so it isn't a good solution.
-
sf_tristanb over 11 yearsIt's better than nothing. If you have a better solution, feel free to add it.
-
relipse about 11 yearsDid phpdocx.com fill your needs Tristan? I too am thinking about buying this (embedHTML() is in the pro version)
-
sf_tristanb about 11 yearsYeah but I must warn you that the library is way beyond good coding standard but it does what we need.