- Code: Select all
ByteArrayOutputStream output = null;
InputStream templateInputStream = new ByteArrayInputStream(docxBytes);
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(templateInputStream);
output = new ByteArrayOutputStream();
Docx4J.toPDF(wordMLPackage, output);
The above code seems to work fine when i run it on my local Windows machine. Unfortunately the same code when deployed on a kubernetes pod throws following exception:
java.lang.ExceptionInInitializerError: Exception java.lang.RuntimeException: org.docx4j.fonts.fop.apps.FOPException: java.io.FileNotFoundException: .docx4j (Permission denied)
java.io.FileNotFoundException: .docx4j (Permission denied) [in thread "http-nio-46000-exec-30"]
at org.docx4j.fonts.IdentityPlusMapper.<clinit>(IdentityPlusMapper.java:77) ~[docx4j-core-11.5.2.jar!/:na]
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.getFontMapper(WordprocessingMLPackage.java:375) ~[docx4j-core-11.5.2.jar!/:na]
The exception is raised when the system tries to call the getFontMapper in WordprocessingMLPackage and create a new IdentityPlusMapper() instance.
I am seeing following comment in the IdentityPlusMapper but doesnt get me much further: This mapper automatically maps document fonts for which the exact font is physically available. Think of this as an identity mapping. For this reason, it will work best on Windows, or a system on which Microsoft fonts have been installed.
Below are the dependencies used:
- Code: Select all
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-core</artifactId>
<version>11.5.2</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-JAXB-ReferenceImpl</artifactId>
<version>11.5.2</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-export-fo</artifactId>
<version>11.5.2</version>
</dependency>