The overhead you see is the repetition of fonts and images. iText doesn't
merge fonts, hence the size. For this kind of application the method that
works best is not the most elegant.

Best Regards,
Paulo Soares

> -----Original Message-----
> From: Bruce Petersen [SMTP:[EMAIL PROTECTED]
> Sent: Tuesday, September 30, 2003 0:51
> To:   '[EMAIL PROTECTED]'
> Subject:      [iText-questions] PdfStamper (etc)
> 
> Greetings!
> 
> I've been using iText for 2+ years for a forms generation application.
> Recently I have started using PdfStamper to simplify the effort of
> overlaying data onto PDF page forms for the following use case (mixed
> pseudo-code ... sorry):
> 
> Document document = localOpen(); // document assumed to be valid
> PdfWriter writer = PdfWriter.getInstance(document, os); // os assumed to
> be
> valid
> document.open();
> PdfContentByte cb = writer.getDirectContent();
> PdfReader formReader = new PdfReader(bytes_from_PDF_resource);
> For 10,000 recipients ...
>    document.newPage();
>    ByteArrayOutputStream baos = new
> ByteArrayOutputStrea(some_reasonable_size);
>    PdfStamper stamper = new PdfStamper(formReader, baos);
>    For each valid field ...
>       setField(with_appropriate_value);
>    End-For
>    stamper.setFormFlattening(true);
>    stamper.close();
>    PdfReader readerTemplate = new PdfReader(baos.toByteArray());
>    cb.addTemplate(writer.getImportedPage(readerTemplate, 1);
>    writer.freeReader(readerTemplate); // ----->>> Adding this line
> prevented
> out of memory exceptions for iterations of this size
> End-For
> doccument.close();
> 
> The above works great, with one exception ... it creates an enormous PDF
> file (approx. 200mb).  The following code produces a much smaller PDF file
> (approx. 15mb), but is not nearly as elegant as above:
> 
> Document document = localOpen(); // document assumed to be valid
> PdfWriter writer = PdfWriter.getInstance(document, os); // os assumed to
> be
> valid
> document.open();
> PdfContentByte cb = writer.getDirectContent();
> PdfReader formReader = new PdfReader(bytes_from_PDF_resource);
> // Code that determines AcroForm field coordinates omitted
> PdfImportedPage imported = writer.getImportedPage(formReader, 1);
> For 10,000 recipients ...
>    document.newPage();
>    cb.addTemplate(imported);
>    For each valid field ...
>       Use PdfContentByte text writing methods for each rectangle from the
> AcroForm above
>    End-For
> End-For
> doccument.close();
>    
> A lot of detail presented, a lot omitted.  Hopefully this tells enough of
> the story to invite your suggestions or comments.
> 
> Cheers,
> 
> Bruce
> 
> 
> 
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> iText-questions mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/itext-questions


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to