Well, my 2 cents, when it comes to the word Word 2007 docx , the words 97-2004 doc , pdf and all other types of MS Office who want to "convert from y to z but in real life they donβt want to be." In my experience, you cannot convert with LibreOffice or OpenOffice. Although .doc documents are generally better supported than the word 2007 .docx . In general, it is very difficult to convert .docx to .doc without breaking anything.
.docx also very useful for templates where .doc not binary.
Converting from .doc to PDF was in most cases quite reliable. If you can still influence the design or content of the word document, this may be satisfactory, but in my situation the documents were provided by foreign companies, where even after generating the .docx templates in some scenarios the generated .docx should have been slightly modified with additional text before its creation in PDF.
BASIC WINDOWS BASICS!
All this hiccups led me to conclude that the only true reliable conversion method I found was to use the COM class in PHP, and let MS Word or Excel do all the work for you. I will just give an example of converting .docx to .doc and / or PDF. If you do not have MS Office installed, you can download a trial version in 60 days, which will give you enough space for testing.
COM.net extension is commented out by default in php.ini , just find the line php_com_dotnet.dll and uncomment it like this
extension=php_com_dotnet.dll
Reboot the web server (IIS is not pre, Apache will work just as well).
The code below is a demonstration of how simple it is.
$word = new COM("Word.Application") or die ("Could not initialise Object."); // set it to 1 to see the MS Word window (the actual opening of the document) $word->Visible = 0; // recommend to set to 0, disables alerts like "Do you want MS Word to be the default .. etc" $word->DisplayAlerts = 0; // open the word 2007-2013 document $word->Documents->Open('yourdocument.docx'); // save it as word 2003 $word->ActiveDocument->SaveAs('newdocument.doc'); // convert word 2007-2013 to PDF $word->ActiveDocument->ExportAsFixedFormat('yourdocument.pdf', 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false); // quit the Word process $word->Quit(false); // clean up unset($word);
This is just a small demonstration. I can simply say that if it comes to conversion, it was the only real reliable option that I could use and even recommend.