使用SWFTools将pdf转成swf

1.下载swfTools并安装,下载地址http://www.swftools.org/download.html

2.复制代码到工具类中

 1 ...
 2     
 3     /**
 4      * pdf转swf
 5      * swfDir 存的exe文件路径,我的是:D:/SWFTools/pdf2swf.exe
 6      *
 7      */
 8     private File pdf2swf(File pdfFile) throws Exception {
 9         //下载的文件转成pdf的pdf将要放置的路径
10         String swfPath = templateSwfDir + pdfFile.getName() + ".swf";
11         File swfFile = new File(swfPath);
12         Runtime r = Runtime.getRuntime();
13         if (swfFile.exists()) {
14             swfFile.delete();
15         }
16         if (!pdfFile.exists()) {
17             throw new Exception("程序出现问题,pdf不存在");
18         }
19         try {
20             Process p = r.exec(swfDir + " " + pdfFile.getPath() + " -o " + swfFile.getPath() + " -T 9");
21             loadStream(p.getInputStream());
22             loadStream(p.getErrorStream());
23             loadStream(p.getInputStream());
24         } catch (IOException e) {
25             e.printStackTrace();
26             throw e;
27         }
28         return swfFile;
29     }
30 
31     static String loadStream(InputStream in) throws IOException {
32         int ptr = 0;
33         in = new BufferedInputStream(in);
34         StringBuffer buffer = new StringBuffer();
35         while ((ptr = in.read()) != -1) {
36             buffer.append((char) ptr);
37         }
38         return buffer.toString();
39     }
40 ...

 

posted @ 2020-06-10 10:43  龙谷情Sinoam  阅读(357)  评论(0编辑  收藏  举报
Smiley face