PHP uses OpenOffice to convert Office to PDF format, how to handle

Source: Internet
Author: User
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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.