主頁(yè) > 知識(shí)庫(kù) > PHP調(diào)用OpenOffice實(shí)現(xiàn)word轉(zhuǎn)PDF的方法

PHP調(diào)用OpenOffice實(shí)現(xiàn)word轉(zhuǎn)PDF的方法

熱門標(biāo)簽:網(wǎng)絡(luò)電話400申請(qǐng) 周口網(wǎng)絡(luò)回?fù)芡夂粝到y(tǒng) 外呼系統(tǒng)人工客服 400電話申請(qǐng)辦理 隨州銷售電銷機(jī)器人公司 百度地圖標(biāo)注類型是酒店 福建高頻外呼防封系統(tǒng)哪家好 全國(guó)各省地圖標(biāo)注點(diǎn) 商丘外呼系統(tǒng)好處

最近一直在研究PHP word文檔轉(zhuǎn)PDF,也在網(wǎng)上搜索了很多類似的資料,大多數(shù)都是通過(guò)OpenOffice進(jìn)行轉(zhuǎn)換的。

核心的代碼如下:

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)原來(lái)是轉(zhuǎn)出路徑的問(wèn)題:通過(guò)調(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調(diào)用OpenOffice實(shí)現(xiàn)word轉(zhuǎn)PDF的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Java使用openOffice對(duì)于word的轉(zhuǎn)換及遇到的問(wèn)題解決
  • linux環(huán)境下安裝 openOffice 并啟動(dòng)服務(wù) 的方法
  • Java利用openoffice將doc、docx轉(zhuǎn)為pdf實(shí)例代碼
  • java調(diào)用openoffice將office系列文檔轉(zhuǎn)換為PDF的示例方法
  • Java實(shí)現(xiàn)在線預(yù)覽的示例代碼(openOffice實(shí)現(xiàn))
  • 解決linux下openoffice word文件轉(zhuǎn)PDF中文亂碼的問(wèn)題
  • Java仿文庫(kù)的基本方法(openoffice+swftools+flexPaper)
  • java實(shí)現(xiàn)附件預(yù)覽(openoffice+swftools+flexpaper)實(shí)例
  • 通過(guò)openOffice將office文件轉(zhuǎn)成pdf

標(biāo)簽:南寧 樂(lè)山 迪慶 佛山 定西 六安 十堰 海南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP調(diào)用OpenOffice實(shí)現(xiàn)word轉(zhuǎn)PDF的方法》,本文關(guān)鍵詞  PHP,調(diào)用,OpenOffice,實(shí)現(xiàn),word,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP調(diào)用OpenOffice實(shí)現(xiàn)word轉(zhuǎn)PDF的方法》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于PHP調(diào)用OpenOffice實(shí)現(xiàn)word轉(zhuǎn)PDF的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 企业400电话

    智能AI客服机器人
    15000

    在线订购

    合计11份范本:公司章程+合伙协议+出资协议+合作协议+股权转让协议+增资扩股协议+股权激励+股东会决议+董事会决议

    推薦文章