I've been studying PHP Word documents for PDF, and I've searched the web for a lot of similar data, most of which are converted by OpenOffice. The core code is as follows: function Makepropertyvalue ($name, $value, $osm) {$oStruct = $osm->bridge_getstruct (" Com.sun.star.beans.PropertyValue "); $oStruct->name = $name; $oStruct->value = $value; return $oStruct; }
function Word2pdf ($doc _url, $output _url) {$osm = new COM ("Com.sun.star.ServiceManager") or Die ("please do sure that OpenOffice.org is INSTALLED.N "); $args = Array (Makepropertyvalue ("Hidden", True, $OSM)); $oDesktop = $osm->createinstance ("Com.sun.star.frame.Desktop"); $oWriterDoc = $oDesktop->loadcomponentfromurl ($doc _url, "_blank", 0, $args); $export _args = Array (Makepropertyvalue ("FilterName", "Writer_pdf_export", $OSM)); $oWriterDoc->storetourl ($output _url, $export _args); $oWriterDoc->close (TRUE); }
$doc _file=dirname (__file__). " /11.doc "; The source file, Doc, or WPS can be $output _file=dirname (__file__). /11.pdf "; To turn the file name of the PDF $doc _file = "file:///". $doc _file; $output _file = "file:///". $output _file; $document->word2pdf ($doc _file, $output _file);
Use the above discovery code to keep an error
( ! ) Fatal error:uncaught exception ' com_exception ' with message ' <b>Source:</b> [Automation Bridge] <br/> <b>Description:</b> com.sun.star.task.ErrorCodeIOException: ' In I:\phpStudy\WWW\DocPreview\test2.php On line 27 |
( ! ) Com_exception: <b>Source:</b> [Automation Bridge] <br/><b>Description:</b> Com.sun.star.task.ErrorCodeIOException:in I:\phpStudy\WWW\DocPreview\test2.php on line 27 |
Finally found that the problem is to turn out the path: through debugging to get the above code of the transfer path $output _file is file:///i:\phpstudy\www\docpreview\sdds.pdf. However, the path that storetourl this method needs is this: file:///I:/phpStudy/WWW/DocPreview/sdds.pdf. Therefore, you only need to replace the $output_file "\" with the "/" $doc _file=dirname (__file__). /11.doc "; The source file, Doc, or WPS can be $output _file=dirname (__file__). /11.pdf "; To transfer the file name of the PDF $output _file=str_replace ("\", "/", $output _file); $doc _file = "file:///". $doc _file; $output _file = "file:///". $output _file; $document->word2pdf ($doc _file, $output _file);