import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import com.itextpdf.text.*;
/**
* 讲pdf转化成swf
*/
public class CopyOfLook {
//SWFTools的环境安装路径
public static String SWFTOOLS_PATH="D:"+File.separator+"Program Files"+File.separator+"SWFTools"+File.separator;
//播放器样式文件rfxview.swf的路径
public static String RFXVIEW_SWF_PATH="D:"+File.separator+"rfxview.swf";
public static int pdf2SWF(String sourceFile, String destFile) {
// 目标路径不存在则建立目标路径
File dest = new File(destFile);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
// 源文件不存在则返回 -1
File source = new File(sourceFile);
if (!source.exists()) {
return -1;
}
String SWFTools_HOME = "D:\\Program Files\\SWFTools";
try {
// 调用pdf2swf命令进行转换swfextract -i - sourceFilePath.pdf -o destFilePath.swf //注意linux下的书写 \\pdf2swf.exe
String command = SWFTools_HOME + "\\pdf2swf.exe -i " + sourceFile + " -o "
+ destFile;
Process pro = Runtime.getRuntime().exec(command);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(pro.getInputStream()));
while (bufferedReader.readLine() != null) {
}
pro.waitFor();
// 然后在套播放器 ----
String command1 = "cmd /c \""+SWFTOOLS_PATH+"swfcombine\" "+RFXVIEW_SWF_PATH+" viewport=" + destFile + " -o " + destFile;
Process pro1 = Runtime.getRuntime().exec(command1);
BufferedReader bufferedReader1 = new BufferedReader(new InputStreamReader(pro1.getInputStream()));
while (bufferedReader1.readLine() != null) {
}
try {
pro1.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
return pro.exitValue();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
return 1;
}
public static void main(String[] str) throws MalformedURLException, IOException, DocumentException{
String ywj="D:\\pdf.pdf";
String mbwj="D:\\11.swf";
pdf2SWF(ywj,mbwj );
}
}
PDF转化成swf
最新推荐文章于 2020-06-12 23:57:23 发布