资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php实现openoffice转pdf的方法

小编给大家分享一下php实现openoffice转pdf的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

成都创新互联主营济源网站建设的网络公司,主营网站建设方案,app软件定制开发,济源h5小程序设计搭建,济源网站营销推广欢迎济源等地区企业咨询

php openoffice转pdf的方法:首先下载“openoffice4.1.2”;然后将用户的访问权限为“允许”,并将标识调整为交互式;最后在php环境下运行代码为“function MakePropertyValue(){}”即可。

php实现openoffice转pdf的方法

php操作openoffice把文件转换成pdf

1.上官网, http://www.openoffice.org。下载openoffice4.1.2

‍  2.设置权限

cmd 运行Dcomcnfg.exe->组件服务->计算机->我的电脑->DCOM配置->OpenOffice Service Manager

3.打开openoffice   在进程中查看打开此进程的用户是谁  然后设置此用户的访问权限为允许;

然后将标识调整为交互式;

4.在php环境下运行此代码

Bridge_GetStruct("com.sun.star.beans.PropertyValue");
    $oStruct->Name = $name;
    $oStruct->Value = $value;
    return $oStruct;
}
function word2pdf($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(MakePropertyValue("Hidden",true,$osm));
    //Launch the desktop
        $top = $osm->createInstance("com.sun.star.frame.Desktop");
    //Load the .doc file, and pass in the "Hidden" property from above
    $oWriterDoc = $top->loadComponentFromURL($doc_url,"_blank", 0, $args);
    //Set up the arguments for the PDF output
    $export_args = array(MakePropertyValue("FilterName","writer_pdf_Export",$osm));
    //Write out the PDF
    $oWriterDoc->storeToURL($output_url,$export_args);
    $oWriterDoc->close(true);
}
$doc_file = "file:///D:/wamp/www/study/phpr/201701/11.doc";
$output_file = 'file:///D:/wamp/www/study/phpr/201701/11.pdf';
word2pdf($doc_file,$output_file);
 
?>

注意: 易错点:

1.php首先得开启com组件

php5.45之前在php.ini设置com.allow_dcom = true

php5.45之后extension=php_com_dotnet.dll

2.doc_file和output_file路径必须严格要求为

file:///D:/wamp/www/study/phpr/201701/11.pdf

以上是php实现openoffice转pdf的方法的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


分享名称:php实现openoffice转pdf的方法
文章链接:http://cdkjz.cn/article/ijpgoe.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220