怎么在php中將上傳的word文件轉(zhuǎn)換為PDF格式-創(chuàng)新互聯(lián)

本篇文章為大家展示了怎么在php中將上傳的word文件轉(zhuǎn)換為PDF格式,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

10年積累的做網(wǎng)站、成都網(wǎng)站制作經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先做網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有孫吳免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

代碼如下:


$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');//這個(gè)是絕對(duì)文件地址,如c:\www\1.txt這樣的地址才通過(guò)
// 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

我把以上的代碼做成了一個(gè)函數(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);
}

上述內(nèi)容就是怎么在php中將上傳的word文件轉(zhuǎn)換為PDF格式,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)頁(yè)名稱:怎么在php中將上傳的word文件轉(zhuǎn)換為PDF格式-創(chuàng)新互聯(lián)
文章鏈接:http://www.bm7419.com/article12/dgcggc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、定制網(wǎng)站、網(wǎng)站維護(hù)網(wǎng)站改版、面包屑導(dǎo)航、網(wǎng)站導(dǎo)航

廣告

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

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