日期:2014-05-17  浏览次数:20477 次

利用openoffice把office转成pdf,组件无法使用,请各位大侠帮忙。
本帖最后由 nationzhou 于 2013-05-18 16:42:24 编辑
php 利用openoffice把office转成pdf格式 问题请教
代码如下:

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

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


错误提示:
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `com.sun.star.ServiceManager': 服务器运行失败 ' in D:\APMServ5.2.6\www\htdocs\phpinfo.php:13 Stack trace: #0 D:\APMServ5.2.6\www\htdocs\phpinfo.php(13): com->com('com.sun.star.Se...')

系统环境:apache, php5.2.6, php.ini已开启com,dcom ,
操作系统:win2003,  已安装过OpenOffice3.2, 已设置openoffice相关组件的访问权限,
已用命令行启动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

仍然不能访问,页面大概运行一分钟才提示以上错误,望大侠能帮忙解决,万分感谢!
com组件

------解决方案--------------------
他已经告诉你创建 com.sun.star.ServiceManager 服务失败了
这个与 php 没有关系

你需要先确认你的软件是否工作正常,即在 openoffice 中是否能够转换
如果能成功,再去检查 COM+ 服务是否启动