久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

PHP實現Word與excel等轉換pdf方法

瀏覽:139日期:2022-06-02 14:33:27

下面是操作步驟:

1、安裝免費的openOffice軟件,請至openoffice.org下載最新版本。

2、JDK支持,請自行搜索下載最新版本JDK。

3、安裝完openOffice后,在開始--運行中輸入Dcomcnfg打開組件服務。在組件服務—計算機—我的電腦—DCOMP配置中,選擇

PHP實現Word與excel等轉換pdf方法

在這兩項上分別點擊右鍵屬性,打開屬性面板如下圖:

PHP實現Word與excel等轉換pdf方法

選擇安全選項卡,分別在啟動和激活權限和訪問權限兩項上點自定義,添加Everyone的權限。

選擇標識選項卡,選擇交互式用戶。

4、安裝完openOffice后,請先打開一次確認可以正常運行軟件,然后退出后用命令行運行以下命令。

先到安裝目錄下,例如:C:Program FilesOpenOffice 4program

執行命令:

soffice -headless-accept='socket,host=127.0.0.1,port=8100;urp;' -nofirststartwizard

成功后即在后臺運行了該軟件。

5、如果是php5.4.5以前版本,需要在php.ini里把com.allow_dcom = true打開,即去掉前面的分號。如果是以后版本,需要在php.ini 里增加一行擴展extension=php_com_dotnet.dll,然后檢查php的ext目錄中是否存在該dll文件,如果沒有請自行下載對應版本的dll。然后重啟apache或IIS服務器。

6、代碼實現

/** * office文檔轉換為PDF類 * @author jinzhonghao <954299193@qq.com> created 2015-04-23 */class office2pdf{private $osm;public function __construct(){$this->osm = new COM('com.sun.star.ServiceManager')or die ('Please be sure that OpenOffice.org is installed.n'); }public function MakePropertyValue($name,$value){$oStruct = $this->osm->Bridge_GetStruct('com.sun.star.beans.PropertyValue');$oStruct->Name = $name;$oStruct->Value = $value;return $oStruct;}public function transform($input_url, $output_url){$args = array($this->MakePropertyValue('Hidden',true));$oDesktop = $this->osm->createInstance('com.sun.star.frame.Desktop');$oWriterDoc = $oDesktop->loadComponentFromURL($input_url,'_blank', 0, $args);$export_args = array($this->MakePropertyValue('FilterName','writer_pdf_Export'));$oWriterDoc->storeToURL($output_url,$export_args);$oWriterDoc->close(true);return $this->getPdfPages($output_url);}public function run($input,$output){$input = 'file:///' . str_replace('','/',$input);$output = 'file:///' . str_replace('','/',$output);return $this->transform($input, $output);}/** * 獲取PDF文件頁數的函數獲取 * 文件應當對當前用戶可讀(linux下) * @param [string] $path [文件路徑] * @return int */public function getPdfPages($path){if(!file_exists($path)) return 0;if(!is_readable($path)) return 0;// 打開文件$fp=@fopen($path,'r');if (!$fp) {return 0;}else {$max=0;while(!feof($fp)) {$line = fgets($fp,255);if (preg_match(’//Count [0-9]+/’, $line, $matches)){preg_match(’/[0-9]+/’,$matches[0], $matches2);if ($max<$matches2[0]) $max=$matches2[0];}}fclose($fp);// 返回頁數return $max;}}}

標簽: word
相關文章:
主站蜘蛛池模板: 日土县| 高雄县| 水富县| 安远县| 承德县| 庐江县| 新郑市| 海南省| 三门峡市| 旺苍县| 康马县| 克什克腾旗| 五台县| 年辖:市辖区| 金山区| 平顶山市| 商洛市| 淮阳县| 读书| 遂宁市| 岫岩| 夏津县| 修武县| 清苑县| 辽源市| 扶风县| 岳池县| 汨罗市| 西城区| 东海县| 齐齐哈尔市| 安仁县| 阿城市| 苏尼特右旗| 无极县| 潼关县| 南澳县| 通州区| 民勤县| 无棣县| 通海县|