Mail Merge and Fields |
Here we modify the document by setting field values. Wherever the fields are referenced in the document the output will change.
This type of technique works equally well with normal and mail merge fields.
We read a DOCX file. We set field values we are interested in. Finally we save the output.
string src = TestEnvironment.FixturePath("MailMergeLetter.docx"); string dst = TestEnvironment.OutputPath("Merged.pdf"); Doc doc = new Doc(); doc.SetFile(src); doc.Fields["_BEFORE_"] = ""; doc.Fields["_AFTER_"] = ""; doc.Fields["_TITLE0_"] = "Mr"; doc.Fields["_FIRST0_"] = "Bill"; doc.Fields["_LAST0_"] = "Gates"; doc.Fields["_COMPANY_"] = "Microsoft Inc."; doc.SaveAs(dst);