0

Errors: Caused by: org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml ##docx4j## Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'javax.xml.bind.Unmarshaller javax.xml.bind.JAXBContext.createUnmarshaller()' on a null object reference


dependencies


implementation 'org.docx4j:docx4j-JAXB-ReferenceImpl:8.0.0'
implementation 'org.docx4j:docx4j-JAXB-Internal:8.0.0'
implementation 'org.docx4j:docx4j-JAXB-MOXy:8.0.0'
implementation 'org.docx4j:docx4j-export-fo:8.0.0'
implementation 'org.docx4j:docx4j-MOXy-JAXBContext:3.0.0'
implementation 'stax:stax:1.2.0'
private void Word_to_PDF(String path, String outPath) {
    try {

        InputStream templateInputStream = new FileInputStream(path);
        WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(templateInputStream);
        MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();

        String outputfilepath = outPath;
        FileOutputStream os = new FileOutputStream(outputfilepath);
        Docx4J.toPDF(wordMLPackage,os);
        os.flush();
        os.close();
    } catch (Throwable e) {

        e.printStackTrace();
    }

}

0 Answers0