Go back

Mail merging with PDF documents

We tend to find that mail merge with word documents is a flexible mechanism for customers to control the output of their applications. Be that invoices, emails or reports. Using simple merge merge documents allows the customers to modify the output of the system without having to contact us. We find that the word mail merge solution provided by ASPOSE Words is simple and reliable.

We recently had a customer that required pre made PDF forms to be source of the outputs from their system. After a quick search of the ASPOSE solutions, we found that the ASPOSE PDF Kit had exactly what we needed.

10 lines of code later, we could as easily mail merge against PDF documents as we could against word documents.

MemoryStream outputStream = new MemoryStream();
MemoryStream pdfForm = new MemoryStream(this.Binary.Data);
Form form = new Form(pdfForm, outputStream);

foreach (string fieldName in form.FieldsNames)
{
object fieldValue = "";
if (mailMergeDataSource.GetValue(fieldName, out fieldValue))
form.FillField(fieldName, fieldValue.ToString());
}

form.FlattenAllFields();
form.Save();

return outputStream;

Thank you ASPOSE!

Got a project? Let's work together

Compsoft is a remote working company except for Thursdays when we work together from the Alton Maltings in Alton, Hampshire (UK). Our registered address is detailed below. We'd be delighted to have either a virtual chat with you or to make arrangements to meet in person.