1,安装SWFTOOLS这个工具
直接下一步安装即可注意安装的目录路径不能有空格
2,编写java代码
package com.sunjingyi.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* PDF转为SWF
* @author Sunny
*
*/
public class PDF2SWF {
public static int convertPDF2SWF(String sourcePath, String destPath,
String fileName) throws IOException {
// 目标路径不存在则建立目标路径
File dest = new File(destPath);
if (!dest.exists())
dest.mkdirs();
// 源文件不存在则返回
File source = new File(sourcePath);
if (!source.exists())
return 0;
// 调用pdf2swf命令进行转换,这里写的是swftools的安装路径
String command = "D:\\SWFTools\\SWFTools\\pdf2swf.exe" + " " + sourcePath+ " -o "
+ destPath + fileName + " -f -T 9";
System.out.println(command);
Process pro = Runtime.getRuntime().exec(command);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(pro.getInputStream()));
while (bufferedReader.readLine() != null);
try {
pro.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(pro.exitValue());
return pro.exitValue();
}
/**
* @param args
*/
public static void main(String[] args) {
String sourcePath = "D:\\a.pdf"; //源文件路径
String destPath = "D:\\"; //目标路径
String fileName = "a.swf"; //生成文件名
try {
PDF2SWF.convertPDF2SWF(sourcePath, destPath, fileName);
System.out.println("转换成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
3,测试
1,首先在D盘要有a.pdf这个文件
2,如果成功之后,pro.exitValue();的值为0,其他值为失败
3,之后会在D盘根目录下生成a.swf即转换成功