Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created October 17, 2017 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/332b0f7cf60b2ee5d3b63156f4b165e9 to your computer and use it in GitHub Desktop.
Save bjoerntx/332b0f7cf60b2ee5d3b63156f4b165e9 to your computer and use it in GitHub Desktop.
// create a business object that is used
// as the data source
Invoice invoice = new Invoice() { Name = "Report" };
using (ServerTextControl tx = new ServerTextControl())
{
tx.Create();
LoadSettings ls = new LoadSettings() {
ApplicationFieldFormat = ApplicationFieldFormat.MSWord
};
// load the created template
tx.Load("template.docx", StreamType.WordprocessingML, ls);
// create a new MailMerge engine
using (MailMerge mailMerge = new MailMerge())
{
// connect to ServerTextControl
mailMerge.TextComponent = tx;
// merge the template that is loaded with
// the business object
mailMerge.MergeObject(invoice);
}
// export the document as PDF
tx.Save("test.pdf", StreamType.AdobePDF);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment