@hsiungst,
Please see these sample input and output DOCX / PDF files and try running the following C# code of Aspose.Words for .NET API:
C# Code:
Document doc = new Document("C:\\Temp\\in.docx");
// Extract from Word documents the merged field names
foreach (string mergeFieldName in doc.MailMerge.GetFieldNames())
Console.WriteLine(mergeFieldName);
// Extract from Word documents the content control names
foreach (StructuredDocumentTag contentControl in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
Console.WriteLine(contentControl.Tag); // contentControl.Title
// Replace merged fields with values
doc.MailMerge.Execute(new string[] { "mf1", "mf2" }, new object[] { "merge Field value 1", "merge Field value 2" });
// Replace plain text content controls with values
foreach (StructuredDocumentTag contentControl in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
if (contentControl.SdtType == SdtType.PlainText)
{
contentControl.RemoveAllChildren();
contentControl.AppendChild(new Run(doc, "new value for content Control"));
}
}
// Save final output to DOCX and PDF format
doc.Save("C:\\Temp\\20.8.docx");
doc.Save("C:\\Temp\\20.8.pdf");
Please also refer to following sections of documentation: