Good morning,
I am merging an HTML with a docx. The program has always worked, but with the new docx the program no longer works correctly. The generated docx is generated with unreadable content, even if in reality, when you open the document with word, it is recovered. Why?
My code was:
FileInputStream docxTemplate = new FileInputStream(path + docxTemplateName);
File htmlFile = new File(path + htmlFileName);
String outpuFileName = path + htmlFileName + "_FINALE.docx";
htmlToWordTemplate(docxTemplate,htmlFile,outpuFileName);
private static void htmlToWordTemplate( FileInputStream docxTemplate,File htmlFile,String outputFileName) throws Exception {
WordprocessingMLPackage f = WordprocessingMLPackage.load(docxTemplate);
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(f);
f.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert( htmlFile, null) );
ByteArrayOutputStream out = new ByteArrayOutputStream();
f.save(out);
out.flush();
try(OutputStream outputStream = new FileOutputStream(outputFileName)) {
out.writeTo(outputStream);
}
}
Pom file:
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-ImportXHTML</artifactId>
<version>8.3.11</version>
<!-- <version>8.2.1</version> -->
</dependency>
<!-- https://mvnrepository.com/artifact/org. ... erenceImpl -->
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-JAXB-ReferenceImpl</artifactId>
<version>8.3.14</version>
<!-- <version>8.2.9</version>-->
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.19.1</version>
<!-- <version>1.15.4</version>-->
</dependency>