myselfyours 2017-02-16 06:53 采纳率: 0%
浏览 2531

关于PHP调用com组件实现word转pdf的问题

我按照网上的教程操作了一遍,一直报如下错误:

Fatal error: Call to a member function storeToURL() on a non-object in D:\Xampp\htdocs\ctmgr\protected\modules\proj\views\project\wordtopdf.php on line 47

找了半天也不知道为什么会出现错误,我的代码如下:
<?php

class RunTime //页面执行时间类

{

private $starttime;//页面开始执行时间

private $stoptime;//页面结束执行时间

private $spendtime;//页面执行花费时间

function getmicrotime()//获取返回当前微秒数的浮点数

{

list($usec,$sec)=explode(" ",microtime());

return ((float)$usec + (float)$sec);

}

function start()//页面开始执行函数,返回开始页面执行的时间

{

$this->starttime=$this->getmicrotime();

}

function end()//显示页面执行的时间

{

$this->stoptime=$this->getmicrotime();

$this->spendtime=$this->stoptime-$this->starttime;

//return round($this->spendtime,10);

}

function display()

{

//$this->end();

echo "

运行时间:".round($this->spendtime,10)."秒

";

}

}

/*调用方法 */

$timer=new Runtime();

$timer->start();

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){

$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");

$args = array(MakePropertyValue("Hidden",true,$osm));

$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");

$oWriterDoc = $oDesktop->loadComponentFromURL

($doc_url,"_blank", 0, $args);

$export_args = array(MakePropertyValue

("FilterName","writer_pdf_Export",$osm));

$oWriterDoc->storeToURL($output_url,$export_args);

$oWriterDoc->close(true);

}

$output_dir = "D:/";

$doc_file = "D:/RA.doc";

$pdf_file = "RA.pdf";

$output_file = $output_dir . $pdf_file;

$doc_file = "file:///" . $doc_file;

$output_file = "file:///" . $output_file;

word2pdf($doc_file,$output_file);

$timer->end();

$timer->display();

?>

  • 写回答

3条回答

  • oyljerry 2017-02-16 07:27
    关注

    找到对应出错的代码行数,然后检查对应的对象是否创建成功。应该是对象创建失败,导致调用方法出错

    评论

报告相同问题?