Java Code Examples for org.artofsolving.jodconverter.OfficeDocumentConverter#convert()
The following examples show how to use
org.artofsolving.jodconverter.OfficeDocumentConverter#convert() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseTests.java From kbase-doc with Apache License 2.0 | 8 votes |
protected void convert(File inputFile, File outputFile){ DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration(); configuration.setPortNumber(8100); configuration.setOfficeHome(new File(libreOfficeDirPath)); // configuration.setOfficeHome(new File("D:/Program Files/OpenOffice")); OfficeManager officeManager = configuration.buildOfficeManager(); officeManager.start(); DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, formatRegistry); try { converter.convert(inputFile, outputFile); } catch (Exception e){ e.printStackTrace(); } finally { officeManager.stop(); } }
Example 2
Source File: BaseTests.java From kbase-doc with Apache License 2.0 | 6 votes |
protected void convert(File inputFile, File outputFile, String password){ DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration(); configuration.setPortNumber(8100); configuration.setOfficeHome(new File(libreOfficeDirPath)); // configuration.setOfficeHome(new File("D:/Program Files/OpenOffice")); OfficeManager officeManager = configuration.buildOfficeManager(); officeManager.start(); DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, formatRegistry); Map<String,?> defaultLoadProperties = createDefaultLoadProperties(password); converter.setDefaultLoadProperties(defaultLoadProperties); try { converter.convert(inputFile, outputFile); } catch (Exception e){ e.printStackTrace(); } finally { officeManager.stop(); } }
Example 3
Source File: ConvertTests.java From kbase-doc with Apache License 2.0 | 6 votes |
@Test public void testConvert() throws IOException { // File inputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1.doc"); File inputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1512561737109.html"); File outputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/" + Calendar.getInstance().getTimeInMillis() + ".docx"); // if (!outputFile.exists()){ // outputFile.createNewFile(); // } DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration(); configuration.setPortNumber(8100); configuration.setOfficeHome(new File("D:/Program Files/LibreOffice")); OfficeManager officeManager = configuration.buildOfficeManager(); officeManager.start(); DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, formatRegistry); try { converter.convert(inputFile, outputFile); } catch (Exception e){ e.printStackTrace(); } finally { officeManager.stop(); } }
Example 4
Source File: OfficePDFConverter.java From sun-wordtable-read with Apache License 2.0 | 6 votes |
public static void doc2Docx(String inputFile,String outputFile) { File pdfFile = new File(outputFile); if (pdfFile.exists()) { pdfFile.delete(); } try{ long startTime = System.currentTimeMillis(); //打开服务 startService(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); DocumentFormat docx = converter.getFormatRegistry().getFormatByExtension("docx"); docx.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "MS Word 2007 XML")); //开始转换 converter.convert(new File(inputFile),new File(outputFile), docx); //关闭 stopService(); System.out.println("运行结束"); }catch (Exception e) { // TODO: handle exception e.printStackTrace(); } }
Example 5
Source File: Doc2DocxUtil.java From sun-wordtable-read with Apache License 2.0 | 6 votes |
public static void doc2Docx(String inputFile,String outputFile) { File pdfFile = new File(outputFile); if (pdfFile.exists()) { pdfFile.delete(); } try{ //打开服务 startService(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); DocumentFormat docx = converter.getFormatRegistry().getFormatByExtension("docx"); docx.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "MS Word 2007 XML")); //开始转换 converter.convert(new File(inputFile),new File(outputFile), docx); //关闭 stopService(); System.out.println("运行结束"); }catch (Exception e) { // TODO: handle exception e.printStackTrace(); } }
Example 6
Source File: DocConverter.java From document-management-system with GNU General Public License v2.0 | 6 votes |
/** * Convert a document format to another one. */ public void convert(File inputFile, String mimeType, File outputFile) throws ConversionException { log.debug("convert({}, {}, {})", new Object[]{inputFile, mimeType, outputFile}); if (Config.SYSTEM_OPENOFFICE_PATH.equals("") && Config.SYSTEM_OPENOFFICE_SERVER.equals("")) { throw new ConversionException(Config.PROPERTY_SYSTEM_OPENOFFICE_PATH + " or " + Config.PROPERTY_SYSTEM_OPENOFFICE_SERVER + " not configured"); } if (!validOpenOffice.contains(mimeType)) { throw new ConversionException("Invalid document conversion MIME type: " + mimeType); } try { if (!Config.SYSTEM_OPENOFFICE_PATH.equals("")) { // Document conversion managed by local OO instance OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); converter.convert(inputFile, outputFile); } else if (!Config.SYSTEM_OPENOFFICE_SERVER.equals("")) { // Document conversion managed by remote conversion server remoteConvert(Config.SYSTEM_OPENOFFICE_SERVER, inputFile, mimeType, outputFile, MimeTypeConfig.MIME_PDF); } } catch (OfficeException e) { throw new ConversionException("Error converting document: " + e.getMessage()); } }
Example 7
Source File: ViewOfficeTools.java From csustRepo with MIT License | 6 votes |
public boolean office2Pdf(String spath,String dpath){ // 转换源文件 File sourceFile = new File(spath); // PDF目标文件 File pdfFile = new File(dpath); // swf文件名不能有中文或者特殊字符,否则会出现找不到文件路径的问题,并且文件名不能存在特殊字符(如%),否则转换会失败 // System.out.println("第一步:生成文件对象,准备转换"); // 转换成pdf文件 if (sourceFile.exists()) { OfficeDocumentConverter converter = new OfficeDocumentConverter(getOfficeManager()); converter.convert(sourceFile,pdfFile); } else { //System.out.println("要转换的文件不存在"); return false; } return true; }
Example 8
Source File: OfficeToPdf.java From kkFileViewOfficeEdit with Apache License 2.0 | 5 votes |
/** * 转换文件 * * @param inputFile * @param outputFilePath_end * @param inputFilePath * @param outputFilePath * @param converter */ public static void converterFile(File inputFile, String outputFilePath_end, String inputFilePath, String outputFilePath, OfficeDocumentConverter converter) { File outputFile = new File(outputFilePath_end); // 假如目标路径不存在,则新建该路径 if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } converter.convert(inputFile, outputFile); }
Example 9
Source File: BaseController.java From kbase-doc with Apache License 2.0 | 5 votes |
/** * 转换文件 * @author eko.zhan at 2018年9月2日 下午2:16:14 * @param originFile * @param targetFile */ protected void convert(File originFile, File targetFile) { WebappContext webappContext = WebappContext.get(servletContext); OfficeDocumentConverter converter = webappContext.getDocumentConverter(); try { long startTime = System.currentTimeMillis(); converter.convert(originFile, targetFile); long conversionTime = System.currentTimeMillis() - startTime; log.info(String.format("successful conversion: %s [%db] to %s in %dms", FilenameUtils.getExtension(originFile.getName()), originFile.length(), FilenameUtils.getExtension(targetFile.getName()), conversionTime)); } catch (Exception e) { e.printStackTrace(); log.error(String.format("failed conversion: %s [%db] to %s; %s; input file: %s", FilenameUtils.getExtension(originFile.getName()), originFile.length(), FilenameUtils.getExtension(targetFile.getName()), e, targetFile.getName())); } }
Example 10
Source File: Doc2DocxUtil.java From sun-wordtable-read with Apache License 2.0 | 5 votes |
private static void transformBinaryWordDocToDocX(File in, File out) { OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); DocumentFormat docx = converter.getFormatRegistry().getFormatByExtension("docx"); docx.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "MS Word 2007 XML")); converter.convert(in, out, docx); }
Example 11
Source File: Doc2DocxUtil.java From sun-wordtable-read with Apache License 2.0 | 5 votes |
private static void transformBinaryWordDocToW2003Xml(File in, File out) { OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);; DocumentFormat w2003xml = new DocumentFormat("Microsoft Word 2003 XML", "xml", "text/xml"); w2003xml.setInputFamily(DocumentFamily.TEXT); w2003xml.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "MS Word 2003 XML")); converter.convert(in, out, w2003xml); }
Example 12
Source File: CommonDocumentConverter.java From sun-wordtable-read with Apache License 2.0 | 5 votes |
@Override public void convert() { OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); System.out.println("转换前处理..."); before(); //开始转换 System.out.println("转换开始执行,["+inputFile+"]转换为["+outputFile+"]..."); if(StringUtils.isNotBlank(extraOutputFormatToNeed)) { DocumentFormat extraFormat = converter.getFormatRegistry().getFormatByExtension(extraOutputFormatToNeed); extraFormat.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", extraOutputFormatMap.get(extraOutputFormatToNeed))); if(needTempFile) { converter.convert(new File(tempFile),new File(outputFile), extraFormat); } else { converter.convert(new File(inputFile),new File(outputFile), extraFormat); } } else { if(needTempFile) { converter.convert(new File(tempFile),new File(outputFile)); } else { converter.convert(new File(inputFile),new File(outputFile)); } } System.out.println("转换后处理..."); after(); System.out.println("转换完成"); }
Example 13
Source File: JodContentTransformer.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void convert(File tempFromFile, DocumentFormat sourceFormat, File tempToFile, DocumentFormat targetFormat) { OfficeDocumentConverter converter = new OfficeDocumentConverter(jodconverter.getOfficeManager()); converter.convert(tempFromFile, tempToFile); }
Example 14
Source File: OfficeToPdf.java From kkFileView with Apache License 2.0 | 5 votes |
public static void converterFile(File inputFile, String outputFilePath_end, OfficeDocumentConverter converter) { File outputFile = new File(outputFilePath_end); // 假如目标路径不存在,则新建该路径 if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } converter.convert(inputFile, outputFile); }
Example 15
Source File: OpenOfficePDFConverter.java From jeecg with Apache License 2.0 | 5 votes |
public void convert2PDF(String inputFile, String pdfFile, String extend) { startService(); log.info("进行文档转换转换:" + inputFile + " --> " + pdfFile); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); try { converter.convert(new File(inputFile), new File(pdfFile)); } catch (Exception e) { e.printStackTrace(); log.info(e.getMessage()); } stopService(); log.info("进行文档转换转换---- 结束----"); }