office转SWF

package com.xinhua.xpm.execute.util;

import java.util.regex.Pattern;

/**
 * 将office文件格式转换为swf格式
 * 
 * @author minqiang
 * @version 创建时间 2018年8月6日 下午2:38:00
 */
public class Office2Swf {

    private static String getCommand(String pdfFile, String swfOutFilePath) {
        String command = null;
        String osName = System.getProperty("os.name");
        if (null == swfOutFilePath || "".equals(swfOutFilePath.trim())) {
            swfOutFilePath = pdfFile.toLowerCase().replaceAll(".pdf", ".swf");
        }
        if (Pattern.matches("Linux.*", osName)) {
            command = "pdf2swf -f " + pdfFile + " " + swfOutFilePath;
        } else if (Pattern.matches("Windows.*", osName)) {
            command = "C:/Program Files/SWFTools/pdf2swf.exe -t " + pdfFile + " -o " + swfOutFilePath + " -T 9";
        } else if (Pattern.matches("Mac.*", osName)) {
        }
        return command;
    }

    public static String pdf2Swf(String pdfInputFilePath, String swfOutFilePath) {
        String command = getCommand(pdfInputFilePath, swfOutFilePath);
        try {
            Process pro = Runtime.getRuntime().exec(command);
            pro.waitFor();
            return pdfInputFilePath.replaceAll("." + getPostfix(pdfInputFilePath), ".swf");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public static String office2Swf(String inputFilePath, String outputSwfPath) {
        String outputPdfPath = null;
        if (null == outputSwfPath || "".equals(outputSwfPath.trim())) {
            outputPdfPath = inputFilePath.replace("." + getPostfix(inputFilePath), ".pdf");
        } else {
            outputPdfPath = outputSwfPath.replace("." + getPostfix(outputSwfPath), ".pdf");
        }
        boolean isSucc = Office2PDF.openOffice2Pdf(inputFilePath, outputPdfPath);
        if (isSucc) {
            outputSwfPath = pdf2Swf(outputPdfPath, outputSwfPath);
        }
        return outputSwfPath;
    }

    private static String getPostfix(String inputFilePath) {
        String postfix = null;
        if (null != inputFilePath && !"".equals(inputFilePath.trim())) {
            int idx = inputFilePath.lastIndexOf(".");
            if (idx > 0) {
                postfix = inputFilePath.substring(idx + 1, inputFilePath.trim().length());
            }
        }
        return postfix;
    }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值