PHP uses OpenOffice to turn office into PDF format
Title find the code from the Internet
function Word2pdf ($doc _url, $output _url)
{
Invoke the OpenOffice.org Service Manager
$OSM = new COM ("Com.sun.star.ServiceManager") or Die ("Sure this OpenOffice.org is installed.\n");
Set the application to remain hidden to avoid flashing the document onscreen
$args = Array ($this->makepropertyvalue ("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.