Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created July 21, 2017 16:08
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/5619ae413a9a291c4b59d2fcf7200bde to your computer and use it in GitHub Desktop.
Save bjoerntx/5619ae413a9a291c4b59d2fcf7200bde to your computer and use it in GitHub Desktop.
protected void Button1_Click(object sender, EventArgs e)
{
// create a DataSet from the sample XML data source
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(Server.MapPath("sample_db.xml"), System.Data.XmlReadMode.Auto);
// load the template
mailMerge1.LoadTemplate(Server.MapPath("template.docx"),
TXTextControl.DocumentServer.FileFormat.WordprocessingML);
// merge the template with data
mailMerge1.Merge(ds.Tables[0]);
// save the document as PDF into a byte array
byte[] data;
mailMerge1.SaveDocumentToMemory(out data,
TXTextControl.BinaryStreamType.AdobePDF, null);
// return the document to the browser for download
Response.Clear();
Response.AddHeader("content-disposition",
String.Format("attachment;filename={0}", "created_by_txtextcontrol.pdf"));
Response.ContentType = "application/pdf";
Response.BinaryWrite(data);
Response.End();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment