php用openoffice转换文档到pdf为什么有的文件可以有的不可以

发布于 2021-11-23 05:39:00 字数 1990 浏览 721 评论 2

<?php
/**
 * Created by JetBrains PhpStorm.
 * User: q
 * Date: 13-1-7
 * Time: 下午2:25
 * To change this template use File | Settings | File Templates.
 */
set_time_limit(0);
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){
    //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:///f:/571c9e50f0a557a2da3d5cc23cc13a8e.doc";
$output_file = 'file:///f:/dev/23.pdf';
word2pdf($doc_file,$output_file);

?>

使用这段来转换doc到pdf 

有的文件能一直成功

有的文件报错

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柳絮泡泡 2021-11-23 22:59:59

能教我下是怎么使用的吗?

把昨日还给我 2021-11-23 20:38:07

好吧终结此贴  原来不是代码错误 

这几个文件openoffice压根就打不开 

wps,word2010都打开的好好的 搞不懂

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文