最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2019年06月10日 11:35:34   作者:jaray  
這篇文章主要介紹了php轉(zhuǎn)換上傳word文件為PDF的方法,結(jié)合實(shí)例形式分析了php基于COM組件針對(duì)word文件的格式轉(zhuǎn)換相關(guān)操作技巧,需要的朋友可以參考下

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

以前用過office組件轉(zhuǎn)換上傳文件word同時(shí)轉(zhuǎn)換為html文件,這次要將word文件轉(zhuǎn)換為pdf格式,網(wǎng)上的方法很多,也很麻煩,也不想在服務(wù)器上再安裝第三方軟件,花了好幾天的時(shí)間,終于在一個(gè)網(wǎng)站上,發(fā)現(xiàn)在了原來用COM組件,在轉(zhuǎn)換為html文件的同時(shí),也能轉(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');//這個(gè)是絕對(duì)文件地址,如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

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

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

更多關(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è)計(jì)算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php正則表達(dá)式用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總

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

相關(guān)文章

最新評(píng)論

扶沟县| 新竹市| 澄江县| 班戈县| 博白县| 北辰区| 上犹县| 桃园县| 依兰县| 四会市| 玛纳斯县| 甘泉县| 平陆县| 三穗县| 兴海县| 靖安县| 盐亭县| 南川市| 郴州市| 宾阳县| 新乡县| 北海市| 新泰市| 绥宁县| 蛟河市| 高阳县| 六盘水市| 贵定县| 宁安市| 蛟河市| 于田县| 柘荣县| 循化| 大方县| 霍山县| 资阳市| 定州市| 郑州市| 盐亭县| 黄陵县| 黄骅市|