https://zhidao.baidu.com/question/1606776577946267867.html?word=www.exiqu.com

\u770b\u4e86\u4e0b\uff0c\u5c31\u662f\u8bf4\u4e0b\u8f7d\u514d\u8d39\uff0c\u89e3\u538b\u5bc6\u7801\u6536\u8d39\u3002\u8fd9\u91cc\u7684\u6536\u8d39\u6307\u7684\u662f\u6263\u9664\u7f51\u7ad9\u8d26\u6237\u91cc\u7684\u4ee3\u5e01\u3002\u53ef\u4ee5\u5145\u94b1\u76f4\u63a5\u8d2d\u4e70\u4ee3\u5e01\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u6bcf\u5929\u5230\u7f51\u7ad9\u505a\u4efb\u52a1\u7b7e\u5230\u4e4b\u7c7b\u83b7\u5f97\u5c11\u91cf\u4ee3\u5e01

package com.cectsims.util;import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import com.artofsolving.jodconverter.DocumentConverter; import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; /** * doc docx\u683c\u5f0f\u8f6c\u6362 */ public class DocConverter { private static final int environment = 1;// \u73af\u5883 1\uff1awindows 2:linux private String fileString;// (\u53ea\u6d89\u53capdf2swf\u8def\u5f84\u95ee\u9898) private String outputPath = "";// \u8f93\u5165\u8def\u5f84 \uff0c\u5982\u679c\u4e0d\u8bbe\u7f6e\u5c31\u8f93\u51fa\u5728\u9ed8\u8ba4\u7684\u4f4d\u7f6e private String fileName; private File pdfFile; private File swfFile; private File docFile; public DocConverter(String fileString) { ini(fileString); } /** * \u91cd\u65b0\u8bbe\u7f6efile * * @param fileString */ public void setFile(String fileString) { ini(fileString); } /** * \u521d\u59cb\u5316 * * @param fileString */ private void ini(String fileString) { this.fileString = fileString; fileName = fileString.substring(0, fileString.lastIndexOf(".")); docFile = new File(fileString); pdfFile = new File(fileName + ".pdf"); swfFile = new File(fileName + ".swf"); } /** * \u8f6c\u4e3aPDF * * @param file */ private void doc2pdf() throws Exception { if (docFile.exists()) { if (!pdfFile.exists()) { OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); try { connection.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(docFile, pdfFile); // close the connection connection.disconnect(); System.out.println("****pdf\u8f6c\u6362\u6210\u529f\uff0cPDF\u8f93\u51fa\uff1a" + pdfFile.getPath()+ "****"); } catch (java.net.ConnectException e) { e.printStackTrace(); System.out.println("****swf\u8f6c\u6362\u5668\u5f02\u5e38\uff0copenoffice\u670d\u52a1\u672a\u542f\u52a8\uff01****"); throw e; } catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) { e.printStackTrace(); System.out.println("****swf\u8f6c\u6362\u5668\u5f02\u5e38\uff0c\u8bfb\u53d6\u8f6c\u6362\u6587\u4ef6\u5931\u8d25****"); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } } else { System.out.println("****\u5df2\u7ecf\u8f6c\u6362\u4e3apdf\uff0c\u4e0d\u9700\u8981\u518d\u8fdb\u884c\u8f6c\u5316****"); } } else { System.out.println("****swf\u8f6c\u6362\u5668\u5f02\u5e38\uff0c\u9700\u8981\u8f6c\u6362\u7684\u6587\u6863\u4e0d\u5b58\u5728\uff0c\u65e0\u6cd5\u8f6c\u6362****"); } } /** * \u8f6c\u6362\u6210 swf */ @SuppressWarnings("unused") private void pdf2swf() throws Exception { Runtime r = Runtime.getRuntime(); if (!swfFile.exists()) { if (pdfFile.exists()) { if (environment == 1) {// windows\u73af\u5883\u5904\u7406 try { // Process p = r.exec("D:/Program Files/SWFTools/pdf2swf.exe "+ pdfFile.getPath() + " -o "+ swfFile.getPath() + " -T 9"); Process p = r.exec("C:/Program Files (x86)/SWFTools/pdf2swf.exe "+ pdfFile.getPath() + " -o "+ swfFile.getPath() + " -T 9"); System.out.print(loadStream(p.getInputStream())); System.err.print(loadStream(p.getErrorStream())); System.out.print(loadStream(p.getInputStream())); System.err.println("****swf\u8f6c\u6362\u6210\u529f\uff0c\u6587\u4ef6\u8f93\u51fa\uff1a" + swfFile.getPath() + "****"); if (pdfFile.exists()) { pdfFile.delete(); } } catch (IOException e) { e.printStackTrace(); throw e; } } else if (environment == 2) {// linux\u73af\u5883\u5904\u7406 try { Process p = r.exec("pdf2swf " + pdfFile.getPath() + " -o " + swfFile.getPath() + " -T 9"); System.out.print(loadStream(p.getInputStream())); System.err.print(loadStream(p.getErrorStream())); System.err.println("****swf\u8f6c\u6362\u6210\u529f\uff0c\u6587\u4ef6\u8f93\u51fa\uff1a" + swfFile.getPath() + "****"); if (pdfFile.exists()) { pdfFile.delete(); } } catch (Exception e) { e.printStackTrace(); throw e; } } } else { System.out.println("****pdf\u4e0d\u5b58\u5728,\u65e0\u6cd5\u8f6c\u6362****"); } } else { System.out.println("****swf\u5df2\u7ecf\u5b58\u5728\u4e0d\u9700\u8981\u8f6c\u6362****"); } } static String loadStream(InputStream in) throws IOException { int ptr = 0; in = new BufferedInputStream(in); StringBuffer buffer = new StringBuffer(); while ((ptr = in.read()) != -1) { buffer.append((char) ptr); } return buffer.toString(); } /** * \u8f6c\u6362\u4e3b\u65b9\u6cd5 */ @SuppressWarnings("unused") public boolean conver() { if (swfFile.exists()) { System.out.println("****swf\u8f6c\u6362\u5668\u5f00\u59cb\u5de5\u4f5c\uff0c\u8be5\u6587\u4ef6\u5df2\u7ecf\u8f6c\u6362\u4e3aswf****"); return true; } if (environment == 1) { System.out.println("****swf\u8f6c\u6362\u5668\u5f00\u59cb\u5de5\u4f5c\uff0c\u5f53\u524d\u8bbe\u7f6e\u8fd0\u884c\u73af\u5883windows****"); } else { System.out.println("****swf\u8f6c\u6362\u5668\u5f00\u59cb\u5de5\u4f5c\uff0c\u5f53\u524d\u8bbe\u7f6e\u8fd0\u884c\u73af\u5883linux****"); } try { doc2pdf(); pdf2swf(); } catch (Exception e) { e.printStackTrace(); return false; } if (swfFile.exists()) { return true; } else { return false; } } /** * \u8fd4\u56de\u6587\u4ef6\u8def\u5f84 * * @param s */ public String getswfPath() { if (swfFile.exists()) { String tempString = swfFile.getPath(); tempString = tempString.replaceAll("\\\\", "/"); return tempString; } else { return ""; } } /** * \u8bbe\u7f6e\u8f93\u51fa\u8def\u5f84 */ public void setOutputPath(String outputPath) { this.outputPath = outputPath; if (!outputPath.equals("")) { String realName = fileName.substring(fileName.lastIndexOf("/"), fileName.lastIndexOf(".")); if (outputPath.charAt(outputPath.length()) == '/') { swfFile = new File(outputPath + realName + ".swf"); } else { swfFile = new File(outputPath + realName + ".swf"); } } } }\u8f6c\u6362\u4e3aPDF\uff0c\u7136\u540e\u8f6c\u6362\u4e3aSWF\uff0c\u7f51\u4e0a\u5f88\u591a\u8fd9\u4e2a\u8fc7\u7a0b\u7684\u4ee3\u7801\uff0c\u4f60\u53ef\u4ee5\u770b\u770b

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网