> 
> Let's say I have a PdfReader object and I want to get a PdfTemplate
> object from it for the first page.
> 
> Is the only way to do this through a PdfWriter object?
> 
>       pdfTemplate = writer.getImportedPage(pdfReader, 1);

Pretty much, yeah.  You /can/ make changes within a PdfReader, but those
changes won't be reflected anywhere in a file until you write them out
through a PdfWriter somewhere.  

Note that a PdfStamper is writer-like, but it's actually a wrapper
around "PdfStamperImp extends PdfWriter".  Stamper's "getWriter" will
give you that PdfStamperImp so you can call getImportedPage and whatever
else you might need.




> If not, what is the better way?
> 
> If so, why do I have to create a *writer* object to get a PdfTemplate?
> It seems very strange to me -- I don't want to write out anything at
> that point. Everything's in-memory up to that point.

But at some point you'll need to write it out.  Writers are fairly low
overhead until the rubber meets the road in close(), and the bytes start
flying.

GetImportedPage does things like tracking which resources (images,
fonts, etc) have been imported so that each one is only copied once.
Quite handy, but for that to work, you Require a writer out of the
gate...

...Unless you're willing to do some Risky Hackery in a local branch of
the source where you allow a null writer in a public PdfTemplate
constructor because you're an iText/PDF Expert and Know How Things Work.
Not for the faint of heart.  That sounds remarkably like bragging.  :/

So it's actually possible to do precisely what you want, it's just
Highly Dangerous.

PS: The recommended way of doing what you're doing (combining files with
form fields) goes something like this:

Create a PdfWriter with a blank Document

For each form:
  Fill and flatten into a ByteAarryOutputStream
  Get a reader from the byte[] from the baos
  Get an ImportedPage from the reader into the PdfWriter you whipped up
earlier.
  Draw said ImportedPage in the place[s] you want.

It's rather inefficient to write your forms out then read them back in,
but that's the way you have to do it in iText.  I call this the "walk
and chew gum" problem.  iText can't... within the same class.  You can
Stamp, Copy, CopyFields, and whip up PDFs from scratch in a Writer, but
you can't do all those things at once in the same file.

Ah, Organic Growth.

> 
> --
> Thomas Hauk
> Shaggy Frog Software
> www.shaggyfrog.com
> 


--Mark Storer
  Senior Software Engineer
  Cardiff.com
 
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;

------------------------------------------------------------------------------

_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to