濮阳杆衣贸易有限公司

主頁 > 知識庫 > php轉(zhuǎn)換上傳word文件為PDF的方法【基于COM組件】

php轉(zhuǎn)換上傳word文件為PDF的方法【基于COM組件】

熱門標(biāo)簽:余姚電話機(jī)器人 百度地圖標(biāo)注偏差 開發(fā)地圖標(biāo)注類網(wǎng)站 電銷機(jī)器人問門薩維品牌my 400電話蘭州申請請 廣東廣州在怎么申請400電話 咸寧銷售電銷機(jī)器人系統(tǒng) 外呼系統(tǒng)能給企業(yè)帶來哪些好處 百度地圖怎樣標(biāo)注圖標(biāo)

本文實例講述了php轉(zhuǎn)換上傳word文件為PDF的方法。分享給大家供大家參考,具體如下:

以前用過office組件轉(zhuǎn)換上傳文件word同時轉(zhuǎn)換為html文件,這次要將word文件轉(zhuǎn)換為pdf格式,網(wǎng)上的方法很多,也很麻煩,也不想在服務(wù)器上再安裝第三方軟件,花了好幾天的時間,終于在一個網(wǎng)站上,發(fā)現(xiàn)在了原來用COM組件,在轉(zhuǎn)換為html文件的同時,也能轉(zhuǎn)換為pdf格式,而自己服務(wù)器上已經(jīng)安裝了office2010,這樣只需要改寫一下以前的幾行代碼就可以,代碼如下:

$word = new COM("Word.Application") or die ("Could not initialise Object.");
// set it to 1 to see the MS Word window (the actual opening of the document)
$word->Visible = 0;
// recommend to set to 0, disables alerts like "Do you want MS Word to be the default .. etc"
$word->DisplayAlerts = 0;
// open the word 2007-2013 document 
$word->Documents->Open('yourdocument.docx');//這個是絕對文件地址,如c:\www\1.txt這樣的地址才通過
// save it as word 2003
$word->ActiveDocument->SaveAs('newdocument.doc');//轉(zhuǎn)換成doc格式
// convert word 2007-2013 to PDF
$word->ActiveDocument->ExportAsFixedFormat('yourdocument.pdf', 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);//轉(zhuǎn)換為pdf模式
// quit the Word process
$word->Quit(false);
// clean up
unset($word);

以上代碼的原始地址:http://stackoverflow.com/questions/5538584/convert-word-doc-docx-and-excel-xls-xlsx-to-pdf-with-php

我把以上的代碼做成了一個函數(shù),代碼如下:

function word2pdf($lastfnamedoc,$lastfnamepdf)
{
  $word = new COM("Word.Application") or die ("Could not initialise Object.");
 // set it to 1 to see the MS Word window (the actual opening of the document)
 $word->Visible = 0;
 // recommend to set to 0, disables alerts like "Do you want MS Word to be the default .. etc"
 $word->DisplayAlerts = 0;
 // open the word 2007-2013 document 
 // $word->Documents->Open('3.docx');
// $wordname='D:/www/fa/3.doc';
  $word->Documents->Open($lastfnamedoc);
 // save it as word 2003
// $word->ActiveDocument->SaveAs('4.doc');
 // convert word 2007-2013 to PDF
 // $pdfname='D:/www/fa/3.pdf';
 $word->ActiveDocument->ExportAsFixedFormat($lastfnamepdf, 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
 // quit the Word process
 $word->Quit(false);
 // clean up
 unset($word);
}

我的是doc文件直接換pdf文件,代碼是文件的地址我服務(wù)器的全是絕對地址,否則文件通不過!

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php正則表達(dá)式用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》

希望本文所述對大家PHP程序設(shè)計有所幫助。

您可能感興趣的文章:
  • php實現(xiàn)將HTML頁面轉(zhuǎn)換成word并且保存的方法
  • php ucwords() 函數(shù)將字符串中每個單詞的首字符轉(zhuǎn)換為大寫(實現(xiàn)代碼)
  • php將word轉(zhuǎn)換為html格式代碼分析

標(biāo)簽:十堰 麗江 重慶 臨沂 銅陵 鷹潭 巴彥淖爾 衡陽

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

    智能AI客服机器人
    15000

    在线订购

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

    推薦文章
    辽源市| 洮南市| 嘉义市| 梧州市| 翁牛特旗| 武宣县| 柯坪县| 大庆市| 湖州市| 五莲县| 友谊县| 南投市| 敦煌市| 桂阳县| 兴化市| 阜城县| 新平| 商水县| 惠东县| 邓州市| 黄山市| 岳普湖县| 交城县| 牙克石市| 广饶县| 蒙山县| 栖霞市| 江达县| 金溪县| 盘山县| 驻马店市| 怀集县| 苍溪县| 贞丰县| 会泽县| 罗源县| 陵川县| 镶黄旗| 梧州市| 乌兰察布市| 长宁区|