Mail Merge Document

Mail-Merge Document allows you to easily merge Data with a predefined Document Template and produce a PDF document.

The document template can be of different format like Word as docx or a PDF-Form with form fields.

To do a Mail-Merge follow this simple steps:

  1. Create Word-Template with MailMerge-Fields
    Use Microsoft Word and use its standard functionality to define MailMerge-Fields.
  2. Create List of Data to be merged with Template
    Use the same Field Names you use for the MailMerge-Fields.
  3. Call pdf4me Api with Word-Template and Data and get PDF
    Word-Template and Data will go in the same Api call. Every call could have its own Word-Template. You get back synchronously the generated PDF.

1. Create Word-Template with MailMerge Fields

2. CreateList of Data to be merged with Word-Template

Field NameData
FirstNameMirma
LastNameTester

3. Call pdf4me Api with Word-Template and Data and get PDF

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl 
var req = new MailMergeDoc()
{
    Document = new DocGenDocument()
    {
        DocData = File.ReadAllBytes(@"SimpleLetter.docx"),
        Name = "SimpleLetter.docx",

        MergeData = new MergeData()
        {
            MergeFields = new HashSet()
            {
                new MergeField() { Key = "FirstName", Value = "Mirma" },
                new MergeField() { Key = "LastName", Value = "Tester" },
            }
        }
    }
};
                
var res = Pdf4me.Instance.DocGenerationClient.MailMergeDocAsync(req).ConfigureAwait(false).GetAwaiter().GetResult();

File.WriteAllBytes(res.Document.Name, res.Document.DocData);
Was this article helpful to you? Yes 2 No 1

How can we help?