首页 > 其他分享 >openoffice 文件转化为pdf

openoffice 文件转化为pdf

时间:2023-02-15 14:13:04浏览次数:41  
标签:url doc 转化 openoffice osm output pdf path

/*
 * 转换组件属性设置
 */
function OpenOfficeMakePropertyValue( $name, $value, $osm)
{
    $oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
    $oStruct->Name = $name;
    $oStruct->Value = $value;
    return $oStruct;
}
/* pdf
 * $doc_url:原文件
 * $output_url:存储文件路径
 */
function OpenOfficeWordToPDF( $doc_url, $output_url )
{
    //Invoke the OpenOffice.org service manager
    $osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
    //Set the application to remain hidden to avoid flashing the document onscreen
    $args = array(OpenOfficeMakePropertyValue("Hidden",true,$osm));
    //Launch the desktop
    $oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");

    //Load the .doc file, and pass in the "Hidden" property from above
    $oWriterDoc = $oDesktop->loadComponentFromURL($doc_url,"_blank", 0, $args);
    //Set up the arguments for the PDF output
    $export_args = array(
//        OpenOfficeMakePropertyValue("FilterName","HTML (StarWriter)",$osm) ,
        OpenOfficeMakePropertyValue("FilterName","writer_pdf_Export",$osm) ,
        OpenOfficeMakePropertyValue("Overwrite","true",$osm)
    );
    //Write out the HTML
    $oWriterDoc->storeToURL($output_url,$export_args);
    $oWriterDoc->close(true);
}
//当文件格式为doc、docx时 统一转化pdf
if($_GET['type']=='doc'||$_GET['type']=='docx'||$_GET['type']=='xlsx'||$_GET['type']=='xls'){
    $path='';
    $doc_url='';//原文件名称
    $output_url='';//存储路径名称
    $path=$_GET['path'];//文件绝对路径
    $doc_url='file:///'.$path;//原文件名称
    $nme=pathinfo($path)['filename'];//文件夹名称、文件名称
    $newname='upfiles/tmpview/'.$nme.'/'.$nme.'.pdf';
    $output_url='file:///.$newname;
    $doc_url=str_replace('\\','/',$doc_url);
    $output_url=str_replace('\\','/',$output_url);
    //判断是否已经生成
    if (file_exists($output_url)) {
        $tpl->assign("pdfurl",'../'.$newname);
    }else{
        OpenOfficeWordToPDF($doc_url,$output_url);
        if (file_exists($output_url)) {
            $tpl->assign("pdfurl",'../'.$newname);
        }
    }
}
解决 openoffice 关机后不可使用问题解决
电脑->控制面板->管理工具->组件服务->组件服务->计算机->我的电脑->DCOM配置位置下
OpenOffice Service Manager 服务 右键属性 点击标识 选择交互式用户 应用确认

标签:url,doc,转化,openoffice,osm,output,pdf,path
From: https://www.cnblogs.com/lhjy1/p/17122580.html

相关文章

  • java 实体类Bean与Map互相转化
     1.情景展示java对象与Map之间进行相互转换,如何实现? 2.分析通过org.apache.commons.beanutils.BeanUtils类来实现所需jar包<dependency><groupId>com......
  • K8s:通过 Helmify 实现将 YAML 文件 转化为 Helm Charts
    写在前面分享一个Yaml资源文件转HelmCharts包的小工具helmify博文内容涉及:helmify工具安装,简单使用YAML静态文件转化为HELMcharts包从kustomize输出转......
  • 机器学习 入门 书籍 电子书 pdf
    机器学习入门书籍推荐(机器学习、机器学习实战、深度学习、神经网络与深度学习等),关注公众号:后厂村搬砖工。发送:算法工程师即可 ......
  • 前端导出pdf字体表格被截断问题解决
    最近有个导出pdf的需求,写好之后分页出现字体,表格被截断的问题,影响美观,需要解决。  经过多方查找,发现一个比较好的思路,设置背景色为白色,然后转成图片后,获取截断处图片......
  • 将Markdown文件转换成PDF文件
    1.下载并安装1.1vscode  首先需要说明的是vscode分为System和User两种版本。对于完成该任务来说,并没有太大区别。这里提供一个windows64位的User版本的下载地址:https:......
  • reportlab 生成pdf
    使用fromreportlab.lib.stylesimportgetSampleStyleSheet产生基础格式。如何修改需要的格式:styles=getSampleStyleSheet()style.normal=copy.deepcopy(styles['N......
  • 移动端重排版PDF阅读器比较
    PDF是一种跨操作系统平台的电子文件格式,它能在各种不同的平台上以相同的版式显示。很多扫描书籍或者电子书籍都会采用PDF格式存储。但是移动端由于屏幕的限制,以原版展示PD......
  • .Net Core 操作PDF模板
    1.安装PdfSharpCore   2.PdfSharpCore.Pdf.PdfDocumentdoc=PdfSharpCore.Pdf.IO.PdfReader.Open(temppath,PdfDocumentOpenMode.Modify);//创建一个文档实例,t......
  • 【ArcPy】从地图文档MXD出图(PDF或JPG格式)
    Python工具代码,非Python窗口脚本,可以自行编辑处理一下。#coding=gbkimportarcpyfromarcpyimportmappingimportosdefmain():inFolder=arcpy.GetParamete......
  • 解决一个移动端pdf预览问题
    最近测试提了一个问题,移动端部分页面的pdf,在预览时只能放大一点,和另外的页面放大程度差距很大,希望可以增加这些页面的pdf放大程度,下面记录了解决问题的过程首先看了代码,......