首页 新闻 会员 周边 捐助

pdf2swf工具转换文件问题

0
悬赏园豆:20 [待解决问题]
 1  1 **
 2  2  * 转换成 swf
 3  3  */
 4  4 @SuppressWarnings("unused")
 5  5 private void pdf2swf(String s) throws Exception {
 6  6 Runtime r = Runtime.getRuntime();
 7  7 String s1 = s.substring(0, s.length() - 4) + ".pdf";
 8  8 if (!new File(s1).exists())
 9  9 s1 = s.substring(0, s.length() - 4) + ".PDF";
10 10 String s2 = s.substring(0, s.length() - 4) + ".swf";
11 11 
12 12 if (!swfFile.exists()) {
13 13 if (pdfFile.exists() || pdfFile1.exists()) {
14 14 if (environment == 1) {// windows环境处理
15 15 try {
16 16 Process p = r.exec("c:/swftools/pdf2swf.exe "
17 17 + pdfFile.getPath() + " -o "
18 18 + swfFile.getPath() + " -T 9");
19 19 System.out.print(loadStream(p.getInputStream()));
20 20 System.err.print(loadStream(p.getErrorStream()));
21 21 System.out.print(loadStream(p.getInputStream()));
22 22 System.err.println("****swf转换成功,文件输出:"
23 23 + swfFile.getPath() + "****");
24 24 if (pdfFile.exists()) {
25 25 pdfFile.delete();
26 26 }
27 27 
28 28 } catch (IOException e) {
29 29 e.printStackTrace();
30 30 throw e;
31 31 }
32 32 } else if (environment == 2) {// linux环境处理
33 33 /*
34 34  * try { Process p = r .exec(
35 35  * "pdf2swf -s languagedir=/usr/local/xpdf-chinese-simplified -T 9 -s poly2bitmap -s zoom=150 -s flashversion=9 '"
36 36  * + s1 + "' -o '" + s2 + "'");
37 37  * System.out.print(loadStream(p.getInputStream()));
38 38  * System.err.print(loadStream(p.getErrorStream()));
39 39  * System.err.println("****swf succeed,file path:" +
40 40  * swfFile.getPath() + "****"); if (pdfFile.exists()) {
41 41  * pdfFile.delete(); } } catch (Exception e) {
42 42  * e.printStackTrace(); throw e; }
43 43  */
44 44 try {
45 45 String cmd = "/usr/local/swftools/bin/pdf2swf -s languagedir=/usr/local/xpdf-chinese-simplified -T 9 -s poly2bitmap -s zoom=150 -s flashversion=9 '"
46 46 + s1 + "' -o '" + s2 + "'";
47 47 String[] cmdA = { "/bin/sh", "-c",cmd };
48 48 Process process = Runtime.getRuntime().exec(cmdA);
49 49 LineNumberReader br = new LineNumberReader(
50 50 new InputStreamReader(process.getInputStream()));
51 51 StringBuffer sb = new StringBuffer();
52 52 String line;
53 53 while ((line = br.readLine()) != null) {
54 54 System.out.println(line);
55 55 sb.append(line).append("\n");
56 56 }
57 57 } catch (Exception e) {
58 58 e.printStackTrace();
59 59 }
60 60 }
61 61 } else {
62 62 System.out.println("****pdf not exists****");
63 63 }
64 64 } else {
65 65 System.out.println("****swf is exists****");
66 66 }
67 67 }
68 68 
69 69 static String loadStream(InputStream in) throws IOException {
70 70 
71 71 int ptr = 0;
72 72 in = new BufferedInputStream(in);
73 73 StringBuffer buffer = new StringBuffer();
74 74 
75 75 while ((ptr = in.read()) != -1) {
76 76 buffer.append((char) ptr);
77 77 }
78 78 
79 79 return buffer.toString();
80 80 }
81 81--window环境,已经可以成功运行并转换,有一些特殊的PDF输出不出来SWF文件需要断掉服务才可以输出,其中跟DEBUG跟到loadStream(InputStream in)该方法的in.read()时程序直接结束,求各位大神破解。
程序员的年少的主页 程序员的年少 | 初学一级 | 园豆:182
提问于:2017-07-19 11:27
< >
分享
所有回答(1)
0

建议 代码 用编辑器中的插入代码工具进行排版。

BUTTERAPPLE | 园豆:3190 (老鸟四级) | 2017-07-19 11:37

已修改 谢谢

支持(0) 反对(0) 程序员的年少 | 园豆:182 (初学一级) | 2017-07-20 09:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册