Is it possible to flush output with iText RTF (Java library) gradually? (outofmemory error)

筅森魡賤 提交于 2019-12-22 09:26:10

问题


I'm using iText to create an RTF document. It'll have a few hundred pages when completed. However, I keep getting an outofmemory error, when it's finished adding all the various paragraphs and tables to the document, and it's trying to actually create the RTF file (with document.close();)

I've increased the Runtime memory with -Xmx350m, but it's not feasible to increase it anymore as the users computer won't have that much memory.

Is there a way to gradually write to the RTF document, rather than in a huge block at the end?


回答1:


I found you can set it to explicitly cache on disk rather than memory using:

Document document = new Document();
RtfWriter2 writer2 = RtfWriter2.getInstance(document, new FileOutputStream("document.rtf"));
writer2.getDocumentSettings().setDataCacheStyle(RtfDataCache.CACHE_DISK);
document.open();

This makes it slower to generate but at least it creates the file without error. However, I'd still prefer a method which gradually creates the file if anyone knows one.



来源:https://stackoverflow.com/questions/955396/is-it-possible-to-flush-output-with-itext-rtf-java-library-gradually-outofme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!