PHP uses OpenOffice to turn office into PDF format
Title find the code from the Internet
PHP Code
function Word2pdf ($doc _url, $output _url) {//invoke The OpenOffice.org Service Manager $OSM = new COM ("Com.sun.star.ServiceManager") or Die ("Sure, that OpenOffice.org is installed.\n"); Set the application to remain hidden to avoid flashing the document onscreen $args = Array ($this->makeproperty Value ("Hidden", True, $OSM)); Launch the Desktop $top = $osm->createinstance ("Com.sun.star.frame.Desktop"); Load the. doc file, and pass in the ' Hidden ' property from above $oWriterDoc = $top->loadcomponentfromurl ($doc _url, "_blank", 0, $args); Set up the arguments for the PDF output $export _args = Array ($this->makepropertyvalue ("FilterName", "writer_pdf _export ", $OSM)); Write out the PDF $oWriterDoc->storetourl ($output _url, $export _args); $oWriterDoc->close (TRUE); Public Function test1 () {$output _dir = serverbase. ' Client/files/proj_workaholic/office/pdf/'; $doc _file = serverbase. ' Client/files/proj_workaholic/office/office/helloworld.doc '; $pdf _file = "Hellowworld.pdf"; $output _file = $output _dir. $pdf _file;//$doc _file = "file:///". $doc _file;//$output _file = "file:///". $output _file; $this->word2pdf ($doc _file, $output _file); }test ();
System: Windows XP
Software: openoffice3.3
Server: XAMPP
Php.ini-com.allow_dcom = True
Error: Fatal error:uncaught exception ' com_exception ' with message ' Failed to create COM object ' Com.sun.star.ServiceManager ' In "The Project of Path"
------Solution--------------------
Need to install OpenOffice.org
------Solution--------------------
1. Check if the OpenOffice has been installed.
2. Start the OpenOffice service with the command line:
CD C:\Program files\openoffice.org 3\program
C:\Program files\openoffice.org 3\program>soffice-headless-accept= "Socket,host
=127.0.0.1,port=8100;urp; "-nofirststartwizard
And then try it again.