I'm generating documents using the following process:
- I have a docx template with content controls bindings and an emtpy custom xml part
- I marshall the object graph using XStream into a DomWriter
- I load the docx using LoadFromZipNG
- I inject the serialized object graph into the WordMLDocument using a CustomXMLDataStorage and calling setDocument on it with the generated DOM Document.
- I apply bindings using BindingHandler.applyBindings
- I save the document
I have many images bindings and when I inject too much images I get out of memory exceptions. I'm looking for a strategy to avoid these exceptions and to better handle the generation process without having all images loaded into the memory at a time.
What would you recommand for this? I have seen a post mentioning eXist DB (data-binding-java-f16/improve-performance-and-memory-usage-with-large-templates-t1138.html#p3910) but I don't really understand the suggested approach.
What I was thinking of would be generating the serialized XML directly into a file on the file system by configuring XStream, so that the marshalling step could work without loading all images in the memory. But how can I inject this into the document and apply the bindings whithout loading the whole XML data at a time?
Thanks for your help.