org.artofsolving.jodconverter.document.DocumentFamily Java Examples

The following examples show how to use org.artofsolving.jodconverter.document.DocumentFamily. 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: OfficeDocumentUtils.java    From kkFileViewOfficeEdit with Apache License 2.0 6 votes vote down vote up
public static DocumentFamily getDocumentFamily(XComponent document) throws OfficeException {
    XServiceInfo serviceInfo = cast(XServiceInfo.class, document);
    if (serviceInfo.supportsService("com.sun.star.text.GenericTextDocument")) {
        // NOTE: a GenericTextDocument is either a TextDocument, a WebDocument, or a GlobalDocument
        // but this further distinction doesn't seem to matter for conversions
        return DocumentFamily.TEXT;
    } else if (serviceInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")) {
        return DocumentFamily.SPREADSHEET;
    } else if (serviceInfo.supportsService("com.sun.star.presentation.PresentationDocument")) {
        return DocumentFamily.PRESENTATION;
    } else if (serviceInfo.supportsService("com.sun.star.drawing.DrawingDocument")) {
        return DocumentFamily.DRAWING;
    } else {
        throw new OfficeException("document of unknown family: " + serviceInfo.getImplementationName());
    }
}
 
Example #2
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 #3
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 #4
Source File: OfficeDocumentUtils.java    From kkFileView with Apache License 2.0 6 votes vote down vote up
public static DocumentFamily getDocumentFamily(XComponent document) throws OfficeException {
    XServiceInfo serviceInfo = cast(XServiceInfo.class, document);
    if (serviceInfo.supportsService("com.sun.star.text.GenericTextDocument")) {
        // NOTE: a GenericTextDocument is either a TextDocument, a WebDocument, or a GlobalDocument
        // but this further distinction doesn't seem to matter for conversions
        return DocumentFamily.TEXT;
    } else if (serviceInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")) {
        return DocumentFamily.SPREADSHEET;
    } else if (serviceInfo.supportsService("com.sun.star.presentation.PresentationDocument")) {
        return DocumentFamily.PRESENTATION;
    } else if (serviceInfo.supportsService("com.sun.star.drawing.DrawingDocument")) {
        return DocumentFamily.DRAWING;
    } else {
        throw new OfficeException("document of unknown family: " + serviceInfo.getImplementationName());
    }
}
 
Example #5
Source File: OfficeDocumentUtils.java    From wenku with MIT License 6 votes vote down vote up
public static DocumentFamily getDocumentFamily(XComponent document) throws OfficeException {
    XServiceInfo serviceInfo = cast(XServiceInfo.class, document);
    if (serviceInfo.supportsService("com.sun.star.text.GenericTextDocument")) {
        // NOTE: a GenericTextDocument is either a TextDocument, a WebDocument, or a GlobalDocument
        // but this further distinction doesn't seem to matter for conversions
        return DocumentFamily.TEXT;
    } else if (serviceInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")) {
        return DocumentFamily.SPREADSHEET;
    } else if (serviceInfo.supportsService("com.sun.star.presentation.PresentationDocument")) {
        return DocumentFamily.PRESENTATION;
    } else if (serviceInfo.supportsService("com.sun.star.drawing.DrawingDocument")) {
        return DocumentFamily.DRAWING;
    } else {
        throw new OfficeException("document of unknown family: " + serviceInfo.getImplementationName());
    }
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
Source File: StandardConversionTask.java    From kkFileViewOfficeEdit with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String,?> getStoreProperties(File outputFile, XComponent document) {
    DocumentFamily family = OfficeDocumentUtils.getDocumentFamily(document);
    return outputFormat.getStoreProperties(family);
}
 
Example #11
Source File: StandardConversionTask.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String,?> getStoreProperties(File outputFile, XComponent document) {
    DocumentFamily family = OfficeDocumentUtils.getDocumentFamily(document);
    return outputFormat.getStoreProperties(family);
}
 
Example #12
Source File: StandardConversionTask.java    From wenku with MIT License 4 votes vote down vote up
@Override
protected Map<String,?> getStoreProperties(File outputFile, XComponent document) {
    DocumentFamily family = OfficeDocumentUtils.getDocumentFamily(document);
    return outputFormat.getStoreProperties(family);
}