国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

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

2024-05-05 00:09:32
字體:
供稿:網(wǎng)友

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

以前用過office組件轉(zhuǎn)換上傳文件word同時轉(zhuǎn)換為html文件,這次要將word文件轉(zhuǎn)換為pdf格式,網(wǎng)上的方法很多,也很麻煩,也不想在服務器上再安裝第三方軟件,花了好幾天的時間,終于在一個網(wǎng)站上,發(fā)現(xiàn)在了原來用COM組件,在轉(zhuǎn)換為html文件的同時,也能轉(zhuǎn)換為pdf格式,而自己服務器上已經(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 upunset($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文件,代碼是文件的地址我服務器的全是絕對地址,否則文件通不過!

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


注:相關教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 沙坪坝区| 许昌市| 阆中市| 平安县| 淮北市| 满洲里市| 成安县| 塔河县| 阿城市| 永昌县| 陆良县| 全椒县| 汶上县| 金华市| 康乐县| 二手房| 山东省| 吉林省| 大邑县| 桐城市| 红原县| 郯城县| 濮阳市| 扬中市| 达州市| 赤峰市| 建阳市| 邯郸市| 抚松县| 勃利县| 榆林市| 登封市| 西峡县| 永嘉县| 平泉县| 大宁县| 西充县| 延安市| 望城县| 兴海县| 黎川县|