php openoffice轉pdf的方法:先下載“openoffice4.1.2”;然後將使用者的存取權限為“允許”,並將標識調整為互動式;最後在php環境下執行程式碼為“function MakePropertyValue(){}」即可。

推薦:《PHP影片教學》
php操作openoffice把檔案轉換成pdf
1.上網, http://www.openoffice.org。下載openoffice4.1.2
2.設定權限
cmd 執行Dcomcnfg.exe->元件服務->電腦->我的電腦->DCOM設定- >OpenOffice Service Manager
3.開啟openoffice 在進程中檢視開啟此進程的使用者是誰 然後設定此使用者的存取權限以允許;
然後將識別調整為互動式;
4.在php環境下執行此程式碼
<?php
/**
* Author: 宇翔大魔王
* Date: 17-1-6
* Time: 下午2:25
* TOpdf
*/
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:///D:/wamp/www/study/phpr/201701/11.doc";
$output_file = 'file:///D:/wamp/www/study/phpr/201701/11.pdf';
word2pdf($doc_file,$output_file);
?>注意: 易錯點:
1.php先開啟com元件
45前設定php.ini設定com.allow_dcom = true
php5.45之後extension=php_com_dotnet.dll_doc" file :///D:/wamp/www/study/phpr/201701/11.pdf
#以上是php如何實作openoffice轉pdf的詳細內容。更多資訊請關注PHP中文網其他相關文章!