PHP处理Word转PDF代码示例

本文提供了一段PHP代码示例,用于将Word文档转换为PDF格式。通过使用OpenOffice.org的服务,该脚本实现了文件格式的转换,并确保了转换过程在后台静默执行。

PHP处理Word转PDF代码示例:

  1. <</FONT> ?php
  2. set_time_limit(0);
  3. function MakePropertyValue($name,$value,$osm){
  4. $oStruct = $osm->Bridge_GetStruct
    ("com.sun.star.beans.PropertyValue");
  5. $oStruct->Name = $name;
  6. $oStruct->Value = $value;
  7. return $oStruct;
  8. }
  9. function word2pdf($doc_url, $output_url){
  10. $osm = new COM("com.sun.star.ServiceManager")
    or die ("Please be sure that OpenOffice.org
    is installed.\n");
  11. $args = array(MakePropertyValue("Hidden",true,$osm));
  12. $oDesktop = $osm->createInstance("com.sun.star
    .frame.Desktop");
  13. $oWriterDoc = $oDesktop->loadComponentFromURL
    ($doc_url,"_blank", 0, $args);
  14. $export_args = array(MakePropertyValue
    ("FilterName","writer_pdf_Export",$osm));
  15. $oWriterDoc->storeToURL($output_url,$export_args);
  16. $oWriterDoc->close(true);
  17. }
  18. $output_dir = "D:/LightTPD/htdocs/";
  19. $doc_file = "D:/LightTPD/htdocs/2.doc";
  20. $pdf_file = "2.pdf";
  21. $output_file = $output_dir . $pdf_file;
  22. $doc_file = "file:///" . $doc_file;
  23. $output_file = "file:///" . $output_file;
  24. word2pdf($doc_file,$output_file);
  25. ?>

以上这段代码就是PHP处理Word转PDF的相关实现方法。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值