Page 1 of 1

Performance with docx4j

PostPosted: Fri Nov 25, 2016 7:48 pm
by SMoltok
Hi everybody, hi Jason

We are using docx4j (and we have bought it). We use it to make some PDF (medical prescription, etc...).

Currently, we have 40 users and we need to put the JVM to 4Go because it took too many space in memory and slow down the application in some way.

We are using :

Code: Select all
<!-- Docx4j -->
      <dependency>
         <groupId>org.docx4j</groupId>
         <artifactId>docx4j</artifactId>
         <version>3.3.0</version>
      </dependency>
      
      <dependency>
         <groupId>org.docx4j</groupId>
         <artifactId>docx4j-ImportXHTML</artifactId>
         <version>3.3.0</version>
      </dependency>
      
      <dependency>
                       <groupId>org.docx4j</groupId>
                      <artifactId>docx4j-export-fo</artifactId>
                     <version>3.3.0</version>
              </dependency>



We using DOCX file template (with one logo image), and we replace variables and then convert it to PDF.

Any clue to optimize the use of memory ?

Re: Performance with docx4j

PostPosted: Sat Nov 26, 2016 8:03 am
by jason
The answer to this is going do depend a lot on the specifics of what you are doing, but:

PDF looks like you are using export-FO to get create PDF output. You will find Plutext's commercial PDF Converter uses a lot less resources, and is faster, higher quality etc.

Variable replacement What approach are you using for this? With 3.2.2 beta, you can use StAX instead of JAXB for certain simple scenarios. For one user with a long document, this took peak heap usage from 2GB to 0.5GB. See https://github.com/plutext/docx4j/blob/ ... eStAX.java for an example. This works on a part by part basis: you could use StAX for variable replacement in the main document part, and JAXB to alter metadata in settings or core or extended properties. docx4j will create the JAXB content model when you ask for it, not before.