欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

LINUX下PHP程序实现WORD文件转化为PDF文件的方法

程序员文章站 2023-12-21 21:04:10
本文实例讲述了linux下php程序实现word文件转化为pdf文件的方法。分享给大家供大家参考,具体如下:

本文实例讲述了linux下php程序实现word文件转化为pdf文件的方法。分享给大家供大家参考,具体如下:

<?php
set_time_limit(0);
function makepropertyvalue($name,$value,$osm){
$ostruct = $osm->bridge_getstruct("com.sun.star.beans.propertyvalue");
$ostruct->name = $name;
$ostruct->value = $value;
return $ostruct;
}
function word2pdf($doc_url, $output_url){
$osm = new com("com.sun.star.servicemanager") or die ("please be sure that openoffice.org is installed.\n");
$args = array(makepropertyvalue("hidden",true,$osm));
$odesktop = $osm->createinstance("com.sun.star .frame.desktop");
$owriterdoc = $odesktop->loadcomponentfromurl($doc_url,"_blank", 0, $args);
$export_args = array(makepropertyvalue ("filtername","writer_pdf_export",$osm));
$owriterdoc->storetourl($output_url,$export_args);
$owriterdoc->close(true);
}
$output_dir = "d:/lighttpd/htdocs/";
$doc_file = "d:/lighttpd/htdocs/2.doc";
$pdf_file = "2.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
word2pdf($doc_file,$output_file);
?>

ps:如果大家感觉代码排版不够美观的话,小编在这里推荐一款本站的php格式化美化的排版工具:

php代码在线格式化美化工具:

更多关于php相关内容感兴趣的读者可查看本站专题:《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家php程序设计有所帮助。

上一篇:

下一篇: