1、安装免费的openOffice软件

2、需要JDK支持

3、安装完openOffice后,在开始--运行中输入Dcomcnfg打开组件服务。在组件服务—计算机—我的电脑—DCOMP配置中

4、 先到安装目录下,例如:C:\Program Files\OpenOffice 4\program\

cmd -> soffice -headless-accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

5、需要在php.ini里把com.allow_dcom = true打开,即去掉前面的分号。如果是以后版本,需要在php.ini 里增加一行扩展extension=php_com_dotnet.dll,然后检查php的ext目录中是否存在该dll文件,如果没有请自行下载对应版本的dll。然后重启apache或IIS服务器。

class Office4Pdf
{
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");
//var_dump($input_url);die();
$oWriterDoc = $oDesktop->loadComponentFromURL($input_url,"_blank", 0, $args); $export_args = array($this->MakePropertyValue("FilterName","writer_pdf_Export"));
//var_dump($output_url,$export_args);die();
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
return $this->getPdfPages($output_url);
} public function runs($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;
}
}
}

调用

 static $file = 'C:/phpStudy/';
public function actionPreview()
{ $html = '暂不支持预览';
//名字
$new_name = 'test';
//拼装名字
$source = self::$file.'BOOTEX.txt';
$pdf_url =self::$file.$new_name.".pdf";
$last_url = self::$file.$new_name.".pdf";
$source = iconv("UTF-8", "gbk",$source);
$pdf_url = iconv("UTF-8", "gbk",$pdf_url);
require dirname(dirname(__DIR__)).'/vendor/SDK/OpenOffice/Office4Pdf.php';
$office2pdf = new \Office4Pdf();
$result = $office2pdf->runs($source,$pdf_url);
if($result > 0){
$res = [
'type' =>$new_name,
'url' =>$last_url,
];
var_dump($res);die;
}else{
print_r($html);die;
}
die;
}

PHP windoews调用OpenOffice实现word/ppt转PDF的更多相关文章

  1. Aspose office (Excel,Word,PPT),PDF 在线预览

    前文: 做个备份,拿的是试用版的 Aspose,功能见标题 代码: /// <summary> /// Aspose office (Excel,Word,PPT),PDF 在线预览 // ...

  2. java 调用OpenOffice将word格式文件转换为pdf格式

    一:环境搭建 OpenOffice 下载地址http://www.openoffice.org/ JodConverter 下载地址http://sourceforge.net/projects/jo ...

  3. 调用openoffice Com组件转换成PDF

    //例子 OpenOfficeExportToPDF('file:///C:/SourceFile.odt', 'file:///C:/TargetFile.pdf');   必须为URL格式的路径 ...

  4. 使用openoffice将word文件转换为pdf格式遇到问题:The type com.sun.star.lang.XEventListener cannot be resolved. It is indirectly referenced from required

    The type com.sun.star.lang.XEventListener cannot be resolved. It is indirectly referenced from requi ...

  5. Java通过openOffice实现word,excel,ppt转成pdf实现在线预览

    Java通过openOffice实现word,excel,ppt转成pdf实现在线预览 一.OpenOffice 1.1 下载地址 1.2 JodConverter 1.3 新建实体类PDFDemo ...

  6. Java使用Openoffice将word、ppt转换为PDF

    最近项目中要实现WORD的文件预览功能,我们可以通过将WORD转换成PDF或者HTML,然后通过浏览器预览. OpenOffice OpenOffice.org 是一套跨平台的办公室软件套件,能在 W ...

  7. openoffice excel word 转换pdf 支持本地调用和远程调用

    OpenOffice.org 是一套跨平台的办公室软件套件,能在Windows.Linux.MacOS X (X11)和 Solaris 等操作系统上执行.它与各个主要的办公室软件套件兼容.OpenO ...

  8. asp.net 将ppt,word转化为pdf实现在线浏览详解

    1.首先添加应用:COM里面的Micsosoft Office 12.0 Object Library(VS2013基本都有14.0或者15.0 有的话一样的添加,因为我的没有只有12.0) : 2. ...

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

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

随机推荐

  1. 服务器的公网ip 和内网ip

    原文地址:https://zhidao.baidu.com/question/814783729071869532.html 服务器公网ip 可以用于域名解析ip,服务器远程登录ip,是最主要的服务器 ...

  2. 字符串hash补充(模数情况下)

    字符串模板,在模数意义下的,比较好用 #include<stdio.h> typedef long long LL; /*[字符串哈希算法] 字符串哈希算法的提出,涉及到如何快速地求两个字 ...

  3. Pikachu-File Inclusion(文件包含漏洞)

    File Inclusion(文件包含漏洞)概述 文件包含,是一个功能.在各种开发语言中都提供了内置的文件包含函数,其可以使开发人员在一个代码文件中直接包含(引入)另外一个代码文件. 比如 在PHP中 ...

  4. C# 读取Excel到DataTable两种方式对比

    方式一 OLEDB读取 数据库引擎 优点:读取速度快,依据sheet排序读取 缺点:对于Excel版本依赖强,无法读取指定sheet 错误提示:本地计算机未指定 Microsoft.ACE.OLEDB ...

  5. cmdb实现三种方式

    为什么要做CMDB? 1.实现运维自动化,CMDB是实现运维自动化的基石 2.之前做资产统计的时候,使用execl来统计,为了年底资产审计方便 3.运维日常工作繁琐, 4.运行环境不统一 Agent方 ...

  6. 爬虫学习笔记2requests库和beautifulsoup4库学习笔记

    目录 1.requests库 1.1 安装 2.beautifulsoup4 2.1 常用方法 2.2 bs4 中四大对象种类 2.3 遍历文档树 2.4 搜索文档树 查询id=head的Tag 查询 ...

  7. 对one hot 编码的理解,sklearn. preprocessing.OneHotEncoder()如何进行fit()的?

    查阅了很多资料,逐渐知道了one hot 的编码,但是始终没理解sklearn. preprocessing.OneHotEncoder()如何进行fit()的?自己琢磨了一下,后来终于明白是怎么回事 ...

  8. CVE-2019-9081:laravel框架序列化RCE复现分析

    这里贴上两篇大佬的分析的帖子 本人习惯把平常的一些笔记或者好的帖子记录在自己的博客当中,便于之后遇到同样的漏洞时快速打开思路 1.https://xz.aliyun.com/t/5510#toc-8 ...

  9. Keras 回归 拟合 收集

    案例1 from keras.models import Sequential from keras.layers import Dense, LSTM, Activation from keras. ...

  10. 酸菜鱼的 DP动态规划 刷题记录

    BZOJ1026: [SCOI2009]windy数 数位dp.很多小细节... 代码: #include <bits/stdc++.h> using namespace std; typ ...