开发者社区> 问答> 正文

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

<?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 

有的文件能一直成功

有的文件报错

展开
收起
爱吃鱼的程序员 2020-06-22 22:19:52 627 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

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

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

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

    能教我下是怎么使用的吗?
    2020-06-22 22:20:08
    赞同 展开评论 打赏
问答分类:
PHP
问答地址:
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-深入浅出网络编程与swoole内核-吴镇宇 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载