您好,登錄后才能下訂單哦!
import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; public class PdfConvertUtil { public static String convert(String filePath,String outPath){ File file = new File(filePath); String msg = ""; String realName = outPath+"\\"+file.getName().substring(0,file.getName().length()-3)+"swf"; if("pdf".equals(PdfConvertUtil.getPostfix(filePath))){ try { StringBuffer cmd = new StringBuffer("D:\\swftools\\pdf2swf.exe "); cmd.append(" -o "); //輸出 cmd.append(realName); cmd.append(" -t "); cmd.append(filePath); //輸入文件 cmd.append(" -T -z -s languagedir=D:\\xpdf-chinese-simplified -s flashversion=9");// System.out.println(cmd.toString()); Process p = Runtime.getRuntime().exec(cmd.toString()); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while((line = reader.readLine()) != null){ System.out.println(line); if(line.indexOf("Writing SWF file ") >= 0){ msg = "PDF轉換SWF成功!"; } } if(p.waitFor() != 0){ if(p.exitValue() == 1){ msg = "PDF轉換SWF失敗!"; } } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }else{ msg = "文件不是PDF格式!"; } return msg; } public static String getPostfix(String filePath){ File file = new File(filePath); if(file.isFile()){ String fileName = file.getName(); return fileName.substring(fileName.lastIndexOf('.')+1).toLowerCase(); } return ""; } public static void main(String[] args) { String filePath = "C:\\Users\\Administrator\\Downloads\\nodejs開發指南\\Node.js開發指南.pdf"; System.out.println(PdfConvertUtil.convert(filePath,"C:\\Users\\Administrator\\Downloads\\nodejs開發指南")); } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。