PHP windoews调用OpenOffice实现word/ppt转PDF
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的更多相关文章
- Aspose office (Excel,Word,PPT),PDF 在线预览
前文: 做个备份,拿的是试用版的 Aspose,功能见标题 代码: /// <summary> /// Aspose office (Excel,Word,PPT),PDF 在线预览 // ...
- java 调用OpenOffice将word格式文件转换为pdf格式
一:环境搭建 OpenOffice 下载地址http://www.openoffice.org/ JodConverter 下载地址http://sourceforge.net/projects/jo ...
- 调用openoffice Com组件转换成PDF
//例子 OpenOfficeExportToPDF('file:///C:/SourceFile.odt', 'file:///C:/TargetFile.pdf'); 必须为URL格式的路径 ...
- 使用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 ...
- Java通过openOffice实现word,excel,ppt转成pdf实现在线预览
Java通过openOffice实现word,excel,ppt转成pdf实现在线预览 一.OpenOffice 1.1 下载地址 1.2 JodConverter 1.3 新建实体类PDFDemo ...
- Java使用Openoffice将word、ppt转换为PDF
最近项目中要实现WORD的文件预览功能,我们可以通过将WORD转换成PDF或者HTML,然后通过浏览器预览. OpenOffice OpenOffice.org 是一套跨平台的办公室软件套件,能在 W ...
- openoffice excel word 转换pdf 支持本地调用和远程调用
OpenOffice.org 是一套跨平台的办公室软件套件,能在Windows.Linux.MacOS X (X11)和 Solaris 等操作系统上执行.它与各个主要的办公室软件套件兼容.OpenO ...
- asp.net 将ppt,word转化为pdf实现在线浏览详解
1.首先添加应用:COM里面的Micsosoft Office 12.0 Object Library(VS2013基本都有14.0或者15.0 有的话一样的添加,因为我的没有只有12.0) : 2. ...
- word,excel,ppt转Pdf,Pdf转Swf,通过flexpaper+swftools实现在线预览
其实这是我好几年前的项目,现在再用这种方式我也不建议了,毕竟未来flash慢慢会淘汰,此方式也是因为目测大部分人都装了flash,才这么做的,但是页面展示效果也不好.其实还是考虑收费的控件,毕竟收费的 ...
随机推荐
- EOFError: Compressed file ended before the end-of-stream marker was reached解决办法(在Windows下查看已下载的MNIST数据文件)
出现这个问题的原因是因为文件下载到一半就中断了,解决办法是删除datasets中下载到一半的数据包. 下面以我遇到的问题为例: 我下载数据下载到最后一个包就没有反应了,于是我强制终止了运行,可能是因为 ...
- python3练习100题——004
继续做题-经过python3的测试 原题链接:http://www.runoob.com/python/python-exercise-example4.html 题目:输入某年某月某日,判断这一天是 ...
- Python获取时间范围
import datetime def dateRange(beginDate, endDate): dates = [] dt = datetime.datetime.strptime(beginD ...
- Babel 7 主要改变
1.不支持Node:0.10,0.12,4,5版本 2.更换命名-@babel/xxx 3.移除以年份命名的presets,统一更换成@babel/preset-env 4.移除 ’Stage‘ pr ...
- 题解【洛谷P1896】[SCOI2005]互不侵犯
题面 棋盘类状压 DP 经典题. 我们考虑设 \(dp_{i,j,s}\) 表示前 \(i\) 行已经摆了 \(j\) 个国王,且第 \(i\) 行国王摆放的状态为 \(s\) 的合法方案数. 转移的 ...
- Maven2: Missing artifact but jars are in place
那是因为没有update project. 项目右键,maven-update project.
- linux 安装 Django
安装django的命令 pip install Django ## 这样运行默认安装的是最新版 备注 根据测试在python3.4基础上安装Django 1.8.9正式版是没有问题的,所以要执行下面命 ...
- 【Linux】解决Linux服务器内存不足问题
在Linux服务器上使用Jmeter进行压测的时候,遇到了一个错误: 根据这里的提示: Java HotSpot(TM) -Bit Server VM warning: INFO: os::commi ...
- 数字输出精度 - C语言
1. 浮点型/双精度浮点型 double a=1234.5678; printf("%8.2lf\n",a);// 小数点前的数表示总位数,小数点也算一位 printf(" ...
- 【翻译】浅析为何使用融合CDN是大趋势
使用传统CDN的用户遇到的新问题 随着云计算时代的快速发展,尤其是流媒体大视频时代的到来,用户在是使用过往CDN节点资源调配将面临很多问题: 问题1: 流媒体时代不局限于静态内容分发,直播点播等视频服 ...