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. udp_demo(傻瓜来回发送)

    代码讲解 import socket # 发送数据 def send_data(udp_socket, dest_ip, dest_port): send_msg = input('请输入要发送的数据 ...

  2. SurfaceView 与view区别详解

    SurfaceView 与view区别详解 https://blog.csdn.net/u011339364/article/details/83347109 2018年10月24日 17:20:08 ...

  3. Bell数

    事实上,\[e^{(e^t-1)x}=\sum_{k=0}^{\infty}\frac{B_k(x)}{k!}.\]\[B_n(x)=x\sum_{k=1}^{n}\binom{n-1}{k-1}B_ ...

  4. IntelliJ IDEA 如何彻底删除项目的步骤

    原文参考链接:https://www.jb51.net/article/129473.htm 本文介绍了IntelliJ IDEA 如何彻底删除项目的步骤,分享给大家,顺便给自己留个笔记,具体如下: ...

  5. 题解【洛谷P5767】[NOI1997]最优乘车

    题面 一道很经典的最短路模型转换问题. 考虑如何建图. 我们可以发现,对于每一条公交线路,可以将这条线路上 可以到达的两个点 连一条权值为 \(1\) 的边. 获取一条公交线路上的每一个点可以使用读取 ...

  6. JavaScript 删除某个数组中指定的对象和删除对象属性

    Javascript: 删除指定对象:使用过程中只适合删除对象,如果数组中添加的是类型Function的话是删除不了的. function removeObjWithArr(_arr,_obj) { ...

  7. 项目部署 ubuntu Django uwsgi配置

    1.进入项目文件夹 mkdir uwsgi_file vim uwsgi.ini 写入保存 [uwsgi] chdir = /home/mysite/my_project # 项目目录 module ...

  8. Linux 一些使用工具

    ssh 链接使用工具xshell 下载链接 http://www.onlinedown.net/soft/36383.htm 映射硬盘工具 sftpdriver 安装输入服务器之后链接 并且输入注册码 ...

  9. z3学习档案

    Reference: 看雪-z3巧解逆向 知乎:Z3一把梭 z3 solver学习 使用z3约束求解器解决CTF中的题目 Playing with Z3,hacking the serial chec ...

  10. CSS 美化网页元素

    一.为什么使用CSS 1.有效的传递页面信息 2.使用CSS美化过的页面文本,使页面漂亮.美观,吸引用户 3.可以很好的突出页面的主题内容,使用户第一眼可以看到页面主要内容 4.具有良好的用户体验 二 ...