php如何实现openoffice转pdf

php openoffice转pdf的方法:首先下载“openoffice4.1.2”;然后将用户的访问权限为“允许”,并将标识调整为交互式;最后在php环境下运行代码为“function MakePropertyValue(){}”即a . j M可。

推荐:《PHP视频教程》

php操作openoffX O cice把文件转换成pdf

1.上官网, http://www.openoffice.org。下载openoffice4.1.2

‍ 2.设置权限

cmd 运行Dcomcnfg.exe->组件服务->计算机->我的电脑->DCOM配置->OpenOffice Service ManagerC ) X c $ 5 u M

3.打开openoffice 在进程中查看打开此进程的用户是谁 然& b q p 4 c后设置此用户的访问权限为允许;

然后将标识调整为交互式;

4.在php环境下运行此代码

<?php
/**
* Author: 宇翔大魔王
* Date: 17-1-6
*C ? G t T 6 Time: 下午2:25
* TOpdf
*/
set_time_limit(0);
function MakePropertyValue($name,$value,$osm){
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyVal, ~ @ ^ p w ue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStrucC W b 8 pt;
}
function word2pdf($doc_url, $output_url){
//Invoke the OpenOffice.org service managee J c ! Fr
$o2 A ^ :sm = new COMn $ n Q $ c K("com.sun.star.ServiceManager") or di& # K Be ("Please+ c % V @ y be sure that OpenOffice.org is installed.\n");
//Set the applic} 9 d S s ] Hation to remain hidden to avoid flashingJ p M ; z t t5 H 9 8 . x Khe document onscreenq c E 0 $ f g # T
$args = arc 6 V G N / c `ray(MakePropertyValue("Hidw Y & Aden",true,$osm));
//Laun= ` X ~ @ch the desktop
$top = $osm-&S M ` ( C , Q } :gt;createInstance("com.sun.star.fram; n P 8 # .e.Desktop");
//Load the .doc file, and pass in the "Hidden" property from above
$oWriterDoc = $top->loadComponentFr b ( |romURLa B Q($? 6 Vdoc_url,"_blank", 0,; l K ] $args);
//Set up thK f _ ^ p & z We arguments for the PDF output
$export_args = array(MakePropertyValue("FilterName","writer_pdf_Export",$osm));
//Write out the PDF
$oWri[ + h E mterDoc->stoh n v z nreToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
$doc_file = "fi^ V n h 2 | Dle:///D:/A & a & j b z kwamp/www/study/phpr/201701/11.doc";
$output_file = 'file:///D:/wamp/www/study/phpr/201701/11.pdf';
word2pdf($doc_file,$output_file);
?>

注意: 易错点:

1.php首先得开启com组件

php5.45之前在php.ini设置com.allow_dcom = true

php5.45之后extension=php_com_dotn& 6 W X x Set.t A ) @ , U f % pdll

2.doc_file和output_file路径必须严格要求为

file:///D:/wamp/www/studyU e { I [ Z i v/phpr/201701/11.pdf

以上就是php如何实现openoffice转pdfo * O q Q Q :的详细+ ^ M 5 9 n内容。