這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)怎么在PHP中使用OpenOffice將word轉(zhuǎn)換為PDF,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

核心的代碼如下:
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);
}
$doc_file=dirname(__FILE__)."/11.doc"; //源文件,DOC或者WPS都可以
$output_file=dirname(__FILE__)."/11.pdf"; //欲轉(zhuǎn)PDF的文件名
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
$document->word2pdf($doc_file,$output_file);用上述發(fā)現(xiàn)代碼一直在報(bào)錯(cuò)
( ! ) 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\WWW\DocPreview\test2.php on line 27
( ! ) 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
最后發(fā)現(xiàn)原來是轉(zhuǎn)出路徑的問題:通過調(diào)試得出上述代碼的轉(zhuǎn)出路徑$output_file 是file:///I:\phpStudy\WWW\DocPreview\sdds.pdf。
然而storeToURL這個(gè)方法里面需要的路徑是這樣的:file:///I:/phpStudy/WWW/DocPreview/sdds.pdf。
因此只需要將$output_file的"\"替換為“/”
$doc_file=dirname(__FILE__)."/11.doc"; //源文件,DOC或者WPS都可以
$output_file=dirname(__FILE__)."/11.pdf"; //欲轉(zhuǎn)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轉(zhuǎn)換為PDF了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站欄目:怎么在PHP中使用OpenOffice將word轉(zhuǎn)換為PDF-創(chuàng)新互聯(lián)
轉(zhuǎn)載來于:http://chinadenli.net/article18/gojdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、網(wǎng)頁設(shè)計(jì)公司、響應(yīng)式網(wǎng)站、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容