PHP通过OpenOffice进行转换实现word转PDF

2018-06-22 00:59:11来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

最近一直在研究PHP word文档转PDF,也在网上搜索了很多类似的资料,大多数都是通过OpenOffice进行转换的。

核心的代码如下:

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


$doc_file=dirname(__FILE__)."/11.doc"; //源文件,DOC或者WPS都可以
$output_file=dirname(__FILE__)."/11.pdf"; //欲转PDF的文件名
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
$document->word2pdf($doc_file,$output_file);

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:php实现ajax图片上传的代码

下一篇:实例讲述Yii2使用驼峰命名的形式访问控制器