org.artofsolving.jodconverter.document.DocumentFormat Java Examples

The following examples show how to use org.artofsolving.jodconverter.document.DocumentFormat. 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: OfficePDFConverter.java    From sun-wordtable-read with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: Doc2DocxUtil.java    From sun-wordtable-read with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: CommonDocumentConverter.java    From sun-wordtable-read with Apache License 2.0 5 votes vote down vote up
@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 #4
Source File: OfficeDocumentConverter.java    From wenku with MIT License 5 votes vote down vote up
public void convert(File inputFile, File outputFile, DocumentFormat outputFormat) throws OfficeException {
    String inputExtension = FilenameUtils.getExtension(inputFile.getName());
    DocumentFormat inputFormat = formatRegistry.getFormatByExtension(inputExtension);
    StandardConversionTask conversionTask = new StandardConversionTask(inputFile, outputFile, outputFormat);
    conversionTask.setDefaultLoadProperties(defaultLoadProperties);
    conversionTask.setInputFormat(inputFormat);
    officeManager.execute(conversionTask);
}
 
Example #5
Source File: OfficeDocumentConverter.java    From kkFileView with Apache License 2.0 5 votes vote down vote up
public void convert(File inputFile, File outputFile, DocumentFormat outputFormat) throws OfficeException {
    String inputExtension = FilenameUtils.getExtension(inputFile.getName());
    DocumentFormat inputFormat = formatRegistry.getFormatByExtension(inputExtension);
    StandardConversionTask conversionTask = new StandardConversionTask(inputFile, outputFile, outputFormat);
    conversionTask.setDefaultLoadProperties(defaultLoadProperties);
    conversionTask.setInputFormat(inputFormat);
    officeManager.execute(conversionTask);
}
 
Example #6
Source File: JodContentTransformer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void convert(File tempFromFile, DocumentFormat sourceFormat, File tempToFile,
        DocumentFormat targetFormat)
{
    OfficeDocumentConverter converter = new OfficeDocumentConverter(jodconverter.getOfficeManager());
    converter.convert(tempFromFile, tempToFile);
}
 
Example #7
Source File: Doc2DocxUtil.java    From sun-wordtable-read with Apache License 2.0 5 votes vote down vote up
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 #8
Source File: Doc2DocxUtil.java    From sun-wordtable-read with Apache License 2.0 5 votes vote down vote up
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 #9
Source File: ConvertTests.java    From kbase-doc with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFormatByExtension(){
	DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
	DocumentFormat formatByExtension = formatRegistry.getFormatByExtension("docx");
	System.out.println(formatByExtension.getName());
	Map<DocumentFamily, Map<String, ?>> storePropertiesByFamily = formatByExtension.getStorePropertiesByFamily();
	System.out.println(storePropertiesByFamily.size());
	
}
 
Example #10
Source File: OfficeDocumentConverter.java    From kkFileViewOfficeEdit with Apache License 2.0 5 votes vote down vote up
public void convert(File inputFile, File outputFile, DocumentFormat outputFormat) throws OfficeException {
    String inputExtension = FilenameUtils.getExtension(inputFile.getName());
    DocumentFormat inputFormat = formatRegistry.getFormatByExtension(inputExtension);
    StandardConversionTask conversionTask = new StandardConversionTask(inputFile, outputFile, outputFormat);
    conversionTask.setDefaultLoadProperties(defaultLoadProperties);
    conversionTask.setInputFormat(inputFormat);
    officeManager.execute(conversionTask);
}
 
Example #11
Source File: StandardConversionTask.java    From kkFileViewOfficeEdit with Apache License 2.0 4 votes vote down vote up
public StandardConversionTask(File inputFile, File outputFile, DocumentFormat outputFormat) {
    super(inputFile, outputFile);
    this.outputFormat = outputFormat;
}
 
Example #12
Source File: StandardConversionTask.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
public StandardConversionTask(File inputFile, File outputFile, DocumentFormat outputFormat) {
    super(inputFile, outputFile);
    this.outputFormat = outputFormat;
}
 
Example #13
Source File: StandardConversionTask.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
public void setInputFormat(DocumentFormat inputFormat) {
    this.inputFormat = inputFormat;
}
 
Example #14
Source File: OfficeDocumentConverter.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
public void convert(File inputFile, File outputFile) throws OfficeException {
    String outputExtension = FilenameUtils.getExtension(outputFile.getName());
    DocumentFormat outputFormat = formatRegistry.getFormatByExtension(outputExtension);
    convert(inputFile, outputFile, outputFormat);
}
 
Example #15
Source File: OfficeDocumentConverter.java    From kkFileViewOfficeEdit with Apache License 2.0 4 votes vote down vote up
public void convert(File inputFile, File outputFile) throws OfficeException {
    String outputExtension = FilenameUtils.getExtension(outputFile.getName());
    DocumentFormat outputFormat = formatRegistry.getFormatByExtension(outputExtension);
    convert(inputFile, outputFile, outputFormat);
}
 
Example #16
Source File: StandardConversionTask.java    From wenku with MIT License 4 votes vote down vote up
public StandardConversionTask(File inputFile, File outputFile, DocumentFormat outputFormat) {
    super(inputFile, outputFile);
    this.outputFormat = outputFormat;
}
 
Example #17
Source File: StandardConversionTask.java    From wenku with MIT License 4 votes vote down vote up
public void setInputFormat(DocumentFormat inputFormat) {
    this.inputFormat = inputFormat;
}
 
Example #18
Source File: OfficeDocumentConverter.java    From wenku with MIT License 4 votes vote down vote up
public void convert(File inputFile, File outputFile) throws OfficeException {
    String outputExtension = FilenameUtils.getExtension(outputFile.getName());
    DocumentFormat outputFormat = formatRegistry.getFormatByExtension(outputExtension);
    convert(inputFile, outputFile, outputFormat);
}
 
Example #19
Source File: StandardConversionTask.java    From kkFileViewOfficeEdit with Apache License 2.0 4 votes vote down vote up
public void setInputFormat(DocumentFormat inputFormat) {
    this.inputFormat = inputFormat;
}