/*
* 转换组件属性设置
*/
function OpenOfficeMakePropertyValue( $name, $value, $osm)
{
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
/* pdf
* $doc_url:原文件
* $output_url:存储文件路径
*/
function OpenOfficeWordToPDF( $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(OpenOfficeMakePropertyValue("Hidden",true,$osm));
//Launch the desktop
$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");
//Load the .doc file, and pass in the "Hidden" property from above
$oWriterDoc = $oDesktop->loadComponentFromURL($doc_url,"_blank", 0, $args);
//Set up the arguments for the PDF output
$export_args = array(
// OpenOfficeMakePropertyValue("FilterName","HTML (StarWriter)",$osm) ,
OpenOfficeMakePropertyValue("FilterName","writer_pdf_Export",$osm) ,
OpenOfficeMakePropertyValue("Overwrite","true",$osm)
);
//Write out the HTML
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
//当文件格式为doc、docx时 统一转化pdf
if($_GET['type']=='doc'||$_GET['type']=='docx'||$_GET['type']=='xlsx'||$_GET['type']=='xls'){
$path='';
$doc_url='';//原文件名称
$output_url='';//存储路径名称
$path=$_GET['path'];//文件绝对路径
$doc_url='file:///'.$path;//原文件名称
$nme=pathinfo($path)['filename'];//文件夹名称、文件名称
$newname='upfiles/tmpview/'.$nme.'/'.$nme.'.pdf';
$output_url='file:///.$newname;
$doc_url=str_replace('\\','/',$doc_url);
$output_url=str_replace('\\','/',$output_url);
//判断是否已经生成
if (file_exists($output_url)) {
$tpl->assign("pdfurl",'../'.$newname);
}else{
OpenOfficeWordToPDF($doc_url,$output_url);
if (file_exists($output_url)) {
$tpl->assign("pdfurl",'../'.$newname);
}
}
}
解决 openoffice 关机后不可使用问题解决
电脑->控制面板->管理工具->组件服务->组件服务->计算机->我的电脑->DCOM配置位置下
OpenOffice Service Manager 服务 右键属性 点击标识 选择交互式用户 应用确认