是否可以逐步使用iText RTF(Java库)刷新输出? (outofmemory错误) [英] Is it possible to flush output with iText RTF (Java library) gradually? (outofmemory error)

查看:95
本文介绍了是否可以逐步使用iText RTF(Java库)刷新输出? (outofmemory错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iText创建RTF文档。完成后它将有几百页。但是,当它完成将所有各种段落和表格添加到文档中时,我不断得到一个内存错误,并且它正在尝试实际创建RTF文件(使用document.close();)

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();)

我用-Xmx350m增加了运行时内存,但由于用户计算机没有那么多内存,所以不再增加它。

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.

有没有办法逐步写入RTF文档,而不是最后写入一个巨大的块?

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

推荐答案

我发现您可以使用以下方法将其设置为在磁盘而不是内存上显式缓存:

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.

这篇关于是否可以逐步使用iText RTF(Java库)刷新输出? (outofmemory错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆