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;
}
}