PHP calls OpenOffice implements Word to pdf____php

Source: Internet
Author: User


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);






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.