php實現(xiàn)openoffice轉(zhuǎn)pdf的方法

小編給大家分享一下php實現(xiàn)openoffice轉(zhuǎn)pdf的方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

成都創(chuàng)新互聯(lián)主營濟(jì)源網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件定制開發(fā),濟(jì)源h5小程序設(shè)計搭建,濟(jì)源網(wǎng)站營銷推廣歡迎濟(jì)源等地區(qū)企業(yè)咨詢

php openoffice轉(zhuǎn)pdf的方法:首先下載“openoffice4.1.2”;然后將用戶的訪問權(quán)限為“允許”,并將標(biāo)識調(diào)整為交互式;最后在php環(huán)境下運行代碼為“function MakePropertyValue(){}”即可。

php實現(xiàn)openoffice轉(zhuǎn)pdf的方法

php操作openoffice把文件轉(zhuǎn)換成pdf

1.上官網(wǎng), http://www.openoffice.org。下載openoffice4.1.2

?  2.設(shè)置權(quán)限

cmd 運行Dcomcnfg.exe->組件服務(wù)->計算機(jī)->我的電腦->DCOM配置->OpenOffice Service Manager

3.打開openoffice   在進(jìn)程中查看打開此進(jìn)程的用戶是誰  然后設(shè)置此用戶的訪問權(quán)限為允許;

然后將標(biāo)識調(diào)整為交互式;

4.在php環(huán)境下運行此代碼

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

php5.45之前在php.ini設(shè)置com.allow_dcom = true

php5.45之后extension=php_com_dotnet.dll

2.doc_file和output_file路徑必須嚴(yán)格要求為

file:///D:/wamp/www/study/phpr/201701/11.pdf

以上是php實現(xiàn)openoffice轉(zhuǎn)pdf的方法的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站題目:php實現(xiàn)openoffice轉(zhuǎn)pdf的方法
文章URL:http://bm7419.com/article4/ijpgoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃云服務(wù)器、響應(yīng)式網(wǎng)站、靜態(tài)網(wǎng)站網(wǎng)站設(shè)計、外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計