Created
July 21, 2017 16:08
-
-
Save bjoerntx/5619ae413a9a291c4b59d2fcf7200bde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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