开发者

How can I build a document in iText and then write it to disk separately

I'm trying to write a program to benchmark the iText PDF library and I'd like to separate out disk access if开发者_如何转开发 at all possible. My plan is to write everything into a Document in memory, then take that document and generate a PDF from it. Trouble is, the only way I can see to write the thing to disk is to use PdfWriter, which needs to be started before I begin adding things to the document. Is there any other option? I've been looking, but it's tough to find a good reference to iText online.


There are a huge number of online resources for using iText - not sure where you've tried looking. If google doesn't quite work for you, you can always buy the iText In Action book which is a fantastic resource.

Anyway, wrap your PdfWriter in an output stream that doesn't write to file (like a ByteArrayOutputStream).

PdfWriter.getInstance(document, new ByteArrayOutputStream());

although for your purposes, you may want to hold onto the reference to the BAOS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜