PHP调用OpenOffice实现word转PDF的方法
2018-09-07 15:02
最近一直在研究PHP word文档转PDF,也在网上搜索了很多类似的资料,大多数都是通过OpenOffice进行转换的。
核心的代码如下:
用上述发现代码一直在报错
( ! ) Fatal error: Uncaught exception com_exception with message <b>Source:</b> [automation bridge] <br/><b>Description:</b> com.sun.star.task.ErrorCodeIOException: in I:\phpStudy\
( ! ) com_exception: <b>Source:</b> [automation bridge] <br/><b>Description:</b> com.sun.star.task.ErrorCodeIOException: in I:\phpStudy\WWW\DocPreview\test2.php on line 27
最后发现原来是转出路径的问题:通过调试得出上述代码的转出路径$output_file 是file:///I:\phpStudy\WWW\DocPreview\sdds.pdf。
然而storeToURL这个方法里面需要的路径是这样的:file:///I:/phpStudy/WWW/DocPreview/sdds.pdf。
因此只需要将$output_file的\替换为“/”
$doc_file=dirname(__FILE__)./11.doc; //源文件,DOC或者WPS都可以 $output_file=dirname(__FILE__)./11.pdf; //欲转PDF的文件名 $output_file=str_replace(\\,/,$output_file); $doc_file = file:/// . $doc_file; $output_file = file:/// . $output_file; $document->word2pdf($doc_file,$output_file);
以上这篇PHP调用OpenOffice实现word转PDF的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
文章标题:PHP调用OpenOffice实现word转PDF的方法
文章链接:http://soscw.com/essay/14091.html