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,才这么做的,但是页面展示效果也不好.其实还是考虑收费的控件,毕竟收费的 ...
随机推荐
- 【巨杉数据库SequoiaDB】为“战疫” 保驾护航,巨杉在行动
2020年,我们经历了一个不平静的新春,在这场大的“战疫”中,巨杉数据库也积极响应号召,勇于承担新一代科技企业的社会担当,用自己的行动助力这场疫情防控阻击战! 赋能“战疫”快速响应 巨杉数据库目前服务 ...
- urllib模块提供的urlretrieve()函数使用
urllib模块提供的urlretrieve()函数,urlretrieve()方法直接将远程的数据下载到本地 注意:若是网站有反爬虫的话这个函数会返回 403 Forbidden 参数url:传入的 ...
- 使用mininet创建网络拓扑,使ryu、ovs、主机连接
实验拓扑 控制器:RYU 交换机:s1,s2 主机:h1,h2,h3,h3 联通性(直连): h1<->s1;h2<->s1 h3<->s2;h4<-> ...
- PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) (排序)
At the beginning of every day, the first person who signs in the computer room will unlock the door, ...
- 检测到 LoaderLock Message: 正试图在 OS 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起。
解决方法: 调试状态=>异常(Ctrl+Alt+E)=>Managed Debuggin Assistants=>LoaderLock 的选中状态去掉即可.
- vue报错There are multiple modules with names that only differ in casing. This can lead to unexpected behavior when compiling on a filesystem with other case-semantic. Use equal casing. Compare these mod
今天在开发一个新项目时,当安装完依赖包启动项目后报了一个这个错 There are multiple modules with names that only differ in casing.Thi ...
- ansi sql 语法 切换为 oracle 语法
语句粘贴到 工作表 打开查询构建器 勾选 创建oracle连接 over sql dev 的语法设置调整,否则表别名会右对齐 下面是 转换后的结果,是不是看得舒服多了
- LeetCode subarray-sum-equals-k题解 前缀和+Hash表+枚举——线性做法
文章目录 题意 思路 连续子数组的和sum[i,j] 源码 结果记录 题意 给定一个数组,求连续的子数组的和为k的子数组个数. 思路 连续子数组的和sum[i,j] sum[i,j]=∑k=ijAk( ...
- jQuery---内容复习
内容复习 1. 操作样式 (5) 1.1 css操作 设置单个样式 设置多个样式 获取样式 css(name, value) :设置单个样式 css(obj):设置多个样式 css(name):获取样 ...
- 如何在任意文件下启动jupyter notebook,而不用担心环境配置问题
网上看了很多帖子,说可以写一个bat文件,将bat文件放在你想启动jupyter notebook的地方.可是不行,不能解决我的问题!!!!!!!!!!! 网上是这样说的: ######这为引用### ...