Use OpenOffice to convert Office to PDF, the components can not be used, please heroes help.
This post was last edited by Nationzhou on 2013-05-18 16:42:24
PHP uses OpenOffice to turn office into PDF format questions to ask
The 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 ("Sure this 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);
}
$output _dir = "d:/apmserv5.2.6/www/htdocs/pdf/";
$doc _file = "D:/apmserv5.2.6/www/htdocs/doc/abc.doc";
$pdf _file = "Abc.pdf";
$output _file = $output _dir. $pdf _file;
$doc _file = "file:///". $doc _file;
$output _file = "file:///". $output _file;
Word2pdf ($doc _file, $output _file);
Error message:
Fatal error:uncaught exception ' com_exception ' with message ' Failed to create COM object ' Com.sun.star.ServiceManager ': Service The service failed ' in D:\apmserv5.2.6\www\htdocs\phpinfo.php:13 Stack trace: #0 D:\APMServ5.2.6\www\htdocs\phpinfo.php: com- >com (' Com.sun.star.Se ... ')
System environment: Apache, php5.2.6, PHP.ini has opened com,dcom,
Operating system: Win2003, OpenOffice3.2 has been installed, access to OpenOffice related components has been set,
Started 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
Still cannot access, page probably run a minute to prompt above error, Hope Warrior can help solve, thanks!
------Solution--------------------
He already told you that the creation of the Com.sun.star.ServiceManager service failed.
This is not related to PHP.
You need to verify that your software is working properly, that you can convert it in OpenOffice
If it succeeds, check to see if COM + services are started