views:

28

answers:

1

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.

+1  A: 

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.

Kevin Day