当前位置: 首页 > 工具软件 > office to swf > 使用案例 >

Office 转 PDF & PDF 转 SWF Linux版

卜弘文
2023-12-01

当网站有Office文件对外进行展示时,我们经常是不希望用户进行下载,而是在线进行预览。

这个时候就有必要把Office文件进行转换成SWF文件在网页中显示了

但现在还没有Office文件直接转化成SWF文件的方法,所以现在用PDF进行中转

也就是Office =》 PDF =》 SWF

以下是相应的转化代码(Linux版):Windows版请点:Office 转 PDF & PDF 转 SWF Windows版

----------------------------------------------------------------

安装LibreOffice

注意这里安的是LibreOffice4.4.4.3版本,如果进行默认安装会安装为4.0,在转WORD的时候会出现格式与原Word不同的情况

#!/bin/sh
pathDir=$(cd `dirname $0`; pwd)

yum -y remove openoffice* libreoffice*
tar -zxvf LibreOffice_4.4.4_Linux_x86-64_rpm.tar.gz 
cd LibreOffice_4.4.4.3_Linux_x86-64_rpm/RPMS/
yum -y localinstall *.rpm
cd ${pathDir}
rm -rf LibreOffice_4.4.4.3_Linux_x86-64_rpm
echo "libreoffice instaled"

 

---------------

命令,程序自动判断Linux环境还是Windows环境,调用不同方式进行转换

 

try
    {
        //word "c:\1.doc" "c:\1.pdf" "E:\Projects_GIT\Tools\FlexPaper\pdf2swf.exe" "c:\1.swf"
        //取得文件夹
        var fileInfo = new System.IO.FileInfo(file);
        var path = fileInfo.Directory.FullName;
        var fileName = fileInfo.Name;
        string type = "";
        string officeFile = "";
        string pdfFile = "";
        string swfExe = "";
        string swfFileName = "";
        if (file.IndexOf(".doc") != -1)
        {
            type = "word";
        }
        else if (file.IndexOf(".ppt") != -1)
        {
            type = "powerpoint";
        }
        else if (file.IndexOf(".xls") != -1)
        {
            type = "excel";
        }
        //生成名字
        officeFile = file;
        string pdfName = fileName.Replace(fileInfo.Extension, ".pdf");
        pdfFile = Z.Core.Tools.IOPath.Combine(path, pdfName);
        if (this.DotNet())
        {
            swfExe = Config.PhysicalPath.Instance.Root() + "\\Tools\\FlexPaper\\pdf2swf.exe";
        }
        else
        {
            swfExe = "pdf2swf";
        }
        var swfName = fileName.Replace(fileInfo.Extension, ".swf");
        swfFileName = Z.Core.Tools.IOPath.Combine(path, swfName);
        string cmd = Config.PhysicalPath.Instance.Root() + "\\Tools\\FlexPaper\\OfficeToSWF.exe";
        if (type != "")
        {
            // office 
            if (this.DotNet())
            {
                //如果是Windows的Office的话,那么用OfficeToSWF.exe这个Exe去处理,转PDF和转SWF
                string args = type + " " + officeFile + " " + pdfFile + " " + swfExe + " " + swfFileName;
                var result = Excute(cmd, args);//这里必须要用有窗体的才可以
                LOG.Warn(args + System.Environment.NewLine + result);//日志结果
            }
            else
            {
                //Linux下转Office要先用Libroffice转成PDF,再用PDF2SWF转SWF 
                ///usr/bin/libreoffice --invisible --convert-to pdf:writer_pdf_Export --outdir /use/local/src /use/local/src/123.doc
                cmd = "/usr/bin/libreoffice4.4";
                string args = " --invisible --convert-to pdf:writer_pdf_Export --outdir " + path + " " + officeFile;
                //转Office
                Helper.Cmd.Excute(cmd, args);
                System.Threading.Thread.Sleep(5000);
                //再转 pdf
                args = " " + pdfFile + " -o " + swfFileName + " -f -T 9 -t -s storeallcharacters";
                Helper.Cmd.Excute(swfExe, args);
            }
        }
        else
        {
            // pdf
            string args = " " + file + " -o " + swfFileName + " -f -T 9 -t -s storeallcharacters";
            Helper.Cmd.Excute(swfExe, args);
        }
        if (!System.IO.File.Exists(pdfFile))
        {
            pdfName = null;
        }
        if (!System.IO.File.Exists(swfFileName))
        {
            swfName = null;
        }
        string message = "已处理:" + DateTime.Now.ToAutoShortDate();
        if (pdfName == null
            || swfName == null)
        {
            message = "失败:请确认是否安装并且设置组件的【访问权限】和【标示】";
        }
        else
        {
            message = "已处理:" + DateTime.Now.ToAutoShortDate();
        }
        DoWork(e.Item.Type, e.Item.TargetID, pdfName, swfName, message);
    }
    catch (Exception exx)
    {
        DoWork(e.Item.Type, e.Item.TargetID, null, null, "PDF转换出错:" + exx.Message);
    }

  

转载于:https://www.cnblogs.com/JerryBaxia/p/4776227.html

 类似资料: