word/excel/ppt 2 PDF

时间:2022-09-01 16:53:43

PHP 实现 word/excel/ppt 转换为 PDF

一般最常见的就是利用OpenOffice来转换,来看看实现的核心代码:


class PDFConverter
{
private $com; /**
* need to install openoffice and run in the background
* soffice -headless-accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
*/
public function __construct()
{
try {
$this->com = new COM('com.sun.star.ServiceManager');
} catch (Exception $e) {
die('Please be sure that OpenOffice.org is installed.');
}
} /**
* Execute PDF file(absolute path) conversion
* @param $source [source file]
* @param $export [export file]
*/
public function execute($source, $export)
{
$source = 'file:///' . str_replace('\\', '/', $source);
$export = 'file:///' . str_replace('\\', '/', $export);
$this->convertProcess($source, $export);
} /**
* Get the PDF pages
* @param $pdf_path [absolute path]
* @return int
*/
public function getPages($pdf_path)
{
if (!file_exists($pdf_path)) return 0;
if (!is_readable($pdf_path)) return 0;
if ($fp = fopen($pdf_path, 'r')) {
$page = 0;
while (!feof($fp)) {
$line = fgets($fp, 255);
if (preg_match('/\/Count [0-9]+/', $line, $matches)) {
preg_match('/[0-9]+/', $matches[0], $matches2);
$page = ($page < $matches2[0]) ? $matches2[0] : $page;
}
}
fclose($fp);
return $page;
}
return 0;
} private function setProperty($name, $value)
{
$struct = $this->com->Bridge_GetStruct('com.sun.star.beans.PropertyValue');
$struct->Name = $name;
$struct->Value = $value;
return $struct;
} private function convertProcess($source, $export)
{
$desktop_args = array($this->setProperty('Hidden', true));
$desktop = $this->com->createInstance('com.sun.star.frame.Desktop');
$export_args = array($this->setProperty('FilterName', 'writer_pdf_Export'));
$program = $desktop->loadComponentFromURL($source, '_blank', 0, $desktop_args);
$program->storeToURL($export, $export_args);
$program->close(true);
}
}

更多详细细节可以关注公众号,并回复 word 获取word相关的资料。

word/excel/ppt 2 PDF

原文地址:https://segmentfault.com/a/1190000016861774

word/excel/ppt 2 PDF的更多相关文章

  1. word,excel,ppt转Pdf,Pdf转Swf,通过flexpaper+swftools实现在线预览

    其实这是我好几年前的项目,现在再用这种方式我也不建议了,毕竟未来flash慢慢会淘汰,此方式也是因为目测大部分人都装了flash,才这么做的,但是页面展示效果也不好.其实还是考虑收费的控件,毕竟收费的 ...

  2. word,excel,ppt转pdf

    第一步 需要下载jar包和jacob-1.14.3-x64.dll * <dependency> * <groupId>net.sf.jacob-project</gro ...

  3. PHP 实现 word&sol;excel&sol;ppt 转换为 PDF

    前段时间负责公司内部文件平台的设计,其中有一个需求是要能够在线浏览用户上传的 office 文件. 我的思路是先将 office 转换成 PDF,再通过 pdf.js 插件解析 PDF 文件,使其能在 ...

  4. 21&period;PHP实现Word&sol;Excel&sol;PPT转换为PDF

    参考文档: https://www.cnblogs.com/woider/p/7003481.html http://blog.csdn.net/aoshilang2249/article/detai ...

  5. PDF&sol;WORD&sol;EXCEL&sol;PPT 文档在线阅读

    查资料看了2种解决方法: 1.通过办公软件dll转换,用flans去看 2.通过Aspose转换成pdf格式,在用js前台读pdf(我用的pdf.js) 今天我解决的就是WORD/EXCEL/PPT ...

  6. Atitit&period;office&&num;160&semi;word&&num;160&semi;&&num;160&semi;excel&&num;160&semi;&&num;160&semi;ppt&&num;160&semi;pdf&&num;160&semi;的web在线预览方案与html转换方案&&num;160&semi;attilax&&num;160&semi;总结

    Atitit.office word  excel  ppt pdf 的web在线预览方案与html转换方案 attilax 总结 1. office word  excel pdf 的web预览要求 ...

  7. 在线文档转换API word&comma;excel&comma;ppt等在线文件转pdf、png

    在线文档转换API提供word,excel,ppt等在线文件转pdf.png等,文档:https://www.juhe.cn/docs/api/id/259 接口地址:http://v.juhe.cn ...

  8. java 如何将 word&comma;excel&comma;ppt如何转pdf --openoffice &lpar;1&rpar;

    承上启下,可折叠 上一篇说的是:服务器是windows server时,用jacob将msoffice(指的是word,excel,ppt)转换成pdf. 若被部署项目的服务器是centOS等linu ...

  9. 微信小程序云开发-云存储-下载并打开文件文件(word&sol;excel&sol;ppt&sol;pdf)

    一.wxml文件 1.写文本框,用来获取文件链接. 2.按钮,点击下载文件 <!-- 下载文件(word/excel/ppt/pdf等) --> <view class=" ...

随机推荐

  1. Genome2D编译方法

    Genome2D是一个高效的2D引擎,现在支持Flash(stage3d)和HTML5,因为只有作者一个人在维护,就没开源代码. 最近和作者沟通了下,已经开源啦. 作者划分了几个模块,编译起来不是特别 ...

  2. HTTP状态码206和416

    HTTP 2xx范围内的状态码表明了:"客户端发送的请求已经被服务器接受并且被成功处理了". TTP/1.1 200 OK是HTTP请求成功后的标准响应 HTTP/1.1 206状 ...

  3. JSP&plus;Servlet&plus;javabean&plus;oracle实现页面多条件模糊查询

    之前写过一篇JSP+Servlet+javabean+mysql实现页面多条件模糊查询 使用的是mysql进行的分页查询,mysql用limit控制,而oracle则是用rownum,今天第一次写or ...

  4. sortedArrayUsingComparator

    /* 升序.降序 */ NSArray * array41 = @[@,@,@,@,@,@,@]; NSArray * array42 = [[NSArray alloc]init]; array42 ...

  5. Java基础 —— 面向对象

    面向对象的程序设计: 1. 基本特征:抽象性,封装性,继承性,多态性. 2. 类及成员的访问控制:private:同一类中: default:同一包中: protected:子类中: public:全 ...

  6. UIButton的imageEdgeInsets 和 titleEdgeInsets

    我们知道,在UIButton中有一个UILabel和一个UIImageView,同时还有属性: titleEdgeInsets,imageEdgeInsets.介绍下 imageEdgeInsets ...

  7. VS QT 配置OpenGL

    在visual studio 下编译OpenGL代码出现以下错误,原因是vs没有自带opengl库,需要自己引入 无法解析的外部符号 __imp__glClear@4 无法解析的外部符号 __imp_ ...

  8. react native 第三方组件

    react native 的成功离不开优秀的第三方组件,以下是我见过的一些优秀或者有用的RN第三方组件 按钮 APSL/react-native-button 导航 react-native-simp ...

  9. 小程序41028 form&lowbar;id无效

    如果参数都没有问题的话,那么我的问题来了,你是发给用户自己么?如果不是,那就找到原因了,必须发给本人才可以...我淌过无数条坑,这个坑我服了...官方文档上写的不是很清楚

  10. Color the ball&lpar;HDU1556&rpar;树状数组

    每次对区间内气球进行一次染色,求n次操作后后所有气球染色次数. 树状数组,上下区间更新都可以,差别不大. 1.对于[x,y]区间,对第x-1位减1,第y位加1,之后向上统计 #include<b ...