java实现pdf转换为flash;flash转换为pdf,javapdf,[Java]代码/**
分享于 点击 41360 次 点评:38
java实现pdf转换为flash;flash转换为pdf,javapdf,[Java]代码/**
[Java]代码
/** * * @param sourcePath 源pdf文件 * @param destPath 目标路径 * @param fileName swf文件名如:542315.swf * @return * @throws IOException */ 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命令进行转换 String command = "D:/Program Files/SWFTools/pdf2swf.exe" + " -o " + destPath + "/" + fileName + " -s flashversion=9 " + sourcePath + ""; 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(); } return pro.exitValue(); } public static void coverDOC2PDF(File sourceFile,File pdfFile) throws ConnectException{ OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); try { connection.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(sourceFile, pdfFile); pdfFile.createNewFile(); connection.disconnect(); System.out.println("第二步:转换为PDF格式 路径" + pdfFile.getPath()); } catch (java.net.ConnectException e) { e.printStackTrace(); System.out.println("OpenOffice服务未启动"); throw e; } catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) { e.printStackTrace(); System.out.println("读取文件失败"); throw e; } catch (Exception e){ e.printStackTrace(); try { throw e; } catch (Exception e1) { e1.printStackTrace(); } } }
用户点评