濮阳杆衣贸易有限公司

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

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

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

本文實例講述了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ù)學運算技巧總結(jié)》、《php正則表達式用法總結(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格式代碼分析

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

巨人網(wǎng)絡(luò)通訊聲明:本文標題《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)民參考!
  • 推薦文章
    澎湖县| 大丰市| 济宁市| 奈曼旗| 合作市| 长沙县| 阿巴嘎旗| 怀柔区| 兖州市| 黄骅市| 威远县| 利津县| 甘德县| 铜山县| 大兴区| 江孜县| 班玛县| 盐源县| 罗源县| 沙雅县| 利川市| 阿克苏市| 万年县| 临西县| 泊头市| 鲁山县| 喜德县| 简阳市| 宁强县| 宝坻区| 嘉峪关市| 黑河市| 望都县| 吉水县| 铜梁县| 城市| 天门市| 博爱县| 紫阳县| 南木林县| 鞍山市|