java中调用swftools软件将pdf转化为swf文件 在线预览之步骤二

2019-04-14 18:43发布

在电脑中安装swftools软件 例如: 我的安装路径:E:\安装软件\swftools\pdf2swf.exe 转化工具类: package cn; import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; /** * 将pdf转化为swf文件 * @author * */ public class Converter { private static String pdftoswf = "E:\安装软件\swftools\pdf2swf.exe"; /** * @param sourcePath pdf原路径 * @param destPath 目的路径 * @param fileName 生成swf的文件名 */ public static int convertPDF2SWF(String sourcePath, String destPath, String fileName) throws Exception { //目标路径不存在则建立目标路径 File dest = new File(destPath); if (!dest.exists()) dest.mkdirs(); //源文件不存在则返回 File source = new File(sourcePath); if (!source.exists()) return 0; //调用pdf2swf命令进行转换 String command = pdftoswf + " -o "" + destPath + "\" + fileName + "" -s flashversion=9 "" + sourcePath + """; Process pro = Runtime.getRuntime().exec(command); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(pro.getInputStream())); while (bufferedReader.readLine() != null); try { pro.waitFor(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return pro.exitValue(); } public static void main(String []args) throws Exception { String sourcePath = "C:\Users\Administrator\Desktop\1\1.pdf"; String destPath = "C:\Users\Administrator\Desktop\1\"; String fileName = "test.swf"; Converter.convertPDF2SWF(sourcePath, destPath, fileName); } }