I am using iText.net (in VB.NET) to do a "mail merge" type of application.
The output is a two-sided 4-color postcard with an address on the back
side, and the address database has about 9950 records.  The code I use is
based on the PdfReader example from the tutorial, and looks mostly like
what appears below.

The code works, but consumes an incredible amount of memory, even though
the resulting PDF is quite reasonably sized. "front.pdf" and "back.pdf" are
about 912k and 175k respectively, and a batch of 500 rows (with 1000 pdf
pages) is only about 1513k. ("front.pdf" and "back.pdf" each have an
embedded font, but I don't embed fonts for the address text.)

But while it is running it consumes an incredible amount of memory.
Watching it in Task Manager, although the memory devoted to the program
image itself stays pretty constant, the "commit charge" representing memory
used by the entire system rises by about 600mb when processing 500 records.
If I process 1000 records, it rises to use over a gig of (virtual) memory.
The machine bogs down so badly I have to kill the process.

Is there a more efficient way I should be doing this? Would adding an
acrobat form field to back.pdf and using PdfStamper be less profligate of
memory? Is there anything I can do after every 500 records or so to clear
out the memory, without this causing multiple copies of the XForms to be
added?


dim output as new Document()
dim os as new java.io.FileOutputStream("output.pdf")
dim writer as PdfWriter = PdfWriter.getInstance(output, os)
dim cb as PdfContentByte = writer.getDirectContentUnder()

dim rdrFront as new PdfReader("front.pdf")
dim rdrBack as new PdfReader("back.pdf")
dim pageFront as PdfImportedPage = writer.getImportedPage(rdrFront,1)
dim pageBack as PdfImportedPage = writer.getImportedPage(rdrBack,1)

for each record in the table
   cb.addTemplate(pageFront,0,0)
   output.newPage()
   cb.addTemplate(pageBack,0,0)
   cb.beginText()
   cb.setFontAndSize(...)
   cb.showTextAligned(...) ' several statements here print the address
   output.newPage()
next record

output.close()



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to