Question : PDF Mail Merge with iTextSharp

I would like to "mail merge" letters using iTextsharp. I have a letter template as an existing 1-page PDF with form fields for the address, name and so on. I can successfully populate the letter for a single page, but I am unsure as to how to do this for multiple pages/records.

At the moment, I can fill in one page using PdfStamper as shown below

 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Dim PdfPath As String = "~/Pdf/Letter.pdf"

Dim pdfReader As New PdfReader(HttpContext.Current.Request.MapPath(PdfPath))

Dim pdfStamper As New PdfStamper(pdfReader, m)
pdfStamper.FormFlattening = True 

Dim pdfForm As AcroFields = pdfStamper.AcroFields

'Add in address - AddressString is straight from DB
pdfForm.SetField("Address", AddressString)

pdfReader.Close()
pdfStamper.Close()

Dim Pdfstream As MemoryStream = New MemoryStream(m.ToArray())

Return Pdfstream


I want to be able to use a similar routine to mail merge the template PDF and return it to the user as a memory stream for instant download from a web page. I guess I need to loop through somehow and I also believe I need to use the PdfCopy class but the documentation online is patchy.

Any ideas?

Answer : PDF Mail Merge with iTextSharp

Random Solutions  
 
programming4us programming4us