> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Mark Evertz
> Sent: Thursday, September 16, 2004 8:52 AM
> To: [EMAIL PROTECTED]
> Subject: [iText-questions] Resusing PdfReader and/or PdfStamper
> 
> Hello iText users,
> I would like to create a large amount of (target-) pdf files 
> in a batch
> run from a single (source-) pdf file (changing form field content).
> Performance is a critical aspect in my situation.
> 
> Thus, I tried to reuse iText main objects like PdfStamper and 
> PdfReader.
> My first approach was just to reuse the PdfReader instance, 
> which led to
> the following exception:
> 
> com.lowagie.text.DocumentException: The original document was reused.
> Read it again from file.
> 
> Is there a reason I may not understand? Actually I don't want 
> to read it
> again.
> 

Unfortunately real life usually go against our dreams.

> My second approach has been to reuse both instances - PdfStamper and
> PdfReader. In this case no exception occured, but the created 
> (target-)
> pdf files couldn't be opened:
> 
> reader = (reader!=null)?reader:new PdfReader( getFileName(  ) );
> FileOutputStream stream = new FileOutputStream( 
> getTargetFileName(  ) );
> stamper = (stamper!=null)?stamper:new PdfStamper( reader, stream );
> 
> In my debug statements I noticed that (e.g.) form field 
> values have been
> changed sequentially. For example (values have been choosen
> arbitrarely):
> Form field 'name' of target0.pdf has been changed from '' to 'Name0'
> next iterator step will show:
> Form field 'name' of target1.pdf has been changed from 'Name0' to
> 'Name1'
> 
> Can somebody explain this behaviour to my and more interesting is it
> changeable? Can I somehow reset the content to initial values before
> processing the succeeding file?
> 

PdfStamper changes the PdfReader and what is changed can't be unchanged. However 
things are not that bad:

PdfReader original = new PdfReader(...);

// do the following for each target
PdfReader copy = new PdfReader(original);
PdfStamper stp = new PdfStamper(copy, ...);


Best Regards,
Paulo Soares


-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to