Vjeran Marcinko wrote:

Hi everyone.

I never used iText, only took a quick glance at code examples, and though it
looks great by features I noticed one thing that seems a bit odd, and quite
unsuitable for my needs. Correct me if I'm wrong, but generation of PDF
let's say, consists of following steps :

1. Create Document
2. Create a PdfWriter using Document and OutputStream
3. Open Document
4. Add content to Document
5. Close Document

Menaing that when one is adding content to Document, he is already been
decided where this content should be written to, mixing content
encapsulation with generation. Is there a way to use more tipical (better?)
procedure, practiced by most other libraries that generate some kind of
content (JDOM, JFreeChart....) :

1. Create Document
2. Add content
Suppose you have a document that contains 10.000+ pages.
Are you really going to keep all those pages in memory?
Are you going to store the content in another format first before you convert it to PDF/RTF/...?

3. Create PdfWriter using OutputStream
4. Write Document using PdfWriter

That way Document would only mean encapsulation of content, without mixing
it's meaning with generation. I want to create a "service" object that would
generate PDFs from passed content, which would best be encapsulated as
Document object, but that means that all elements should already be added to
passed Document instance, *before* PDF generation takes place.

Like I said, I never worked with iText, so answer could be so simple that I
would turn out quite dumb :-)

In theory you are probably right, but in many projects the theory doesn't work. We're talking about business processes that have to be very fast (large documents that have to be served in a web-application, batch jobs that take a complete night, etc...) The strength of iText is that it is very performant. It flushes PDF syntax to the OutputStream as soon as you have a full page. You can't do that if you don't specify the Writer first. Remember that patterns are there to help you, but you always have to look at the context. You don't have to use a pattern because of the pattern.

br,
Bruno


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to