Well my 2 cents when it comes to the topic word 2007 docx
, word 97-2004 doc
, pdf
and all other types of MS Office wishing to be "converted from y
to z
but in real they don't wanna be". In my experience so far, conversion with LibreOffice or OpenOffice can't be relied on. Though .doc
documents tend to be better supported than word 2007's .docx
. In general it's very hard to convert the .docx
to .doc
without breaking anything.
.docx
also tend to be extremely useful for templating where .doc
is not for being binary.
The conversion from .doc
to PDF was most of the time quite reliable. If you can still influence the design or content of the word document then this might be satisfying, but in my situation documents were supplied from foreign companies where even after generating the .docx
templates, in some scenario's, the generated .docx
had to be slightly modified with supplement text before it was generated to a PDF.
All this hiccup made me come to the conclusion that the only true reliable conversion method I found was using the COM class in PHP and let the MS Word or Excel Application do all the work for you. I'll just give an example on converting .docx
to .doc
and/or PDF. If you do not have MS Office installed, you can download a trial version of 60 days which would give you enough room for testing purposes.
the COM.net extension is by default commented out in the php.ini
, just search for the line php_com_dotnet.dll
and uncomment it like so
extension=php_com_dotnet.dll
Restart the web server (IIS is not a pre, Apache will work just as well).
The code below is a demonstration on how easy 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 just say that if it comes to conversion, this was the only real reliable option I could use and even recommend.