php 利用openoffice把office转成pdf格式
如题 从网上找到代码
php code function word2pdf($doc_url, $output_url) { //invoke the openoffice.org service manager $osm = new com(com.sun.star.servicemanager) or die (please be sure that 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();
系统:window xp
软件:openoffice3.3
服务器:xampp
php.ini - com.allow_dcom = true
错误:fatal error: uncaught exception 'com_exception' with message 'failed to create com object `com.sun.star.servicemanager' in the project of path
------解决方案--------------------
需要安装openoffice.org
------解决方案--------------------
1、检查一下是否安装过openoffice。
2、用命令行启动openoffice服务:
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
然后再试验一下呢.