Created
July 21, 2017 16:08
-
-
Save bjoerntx/6b453d29c5d20eb93c61d3aec9c11b9c 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 Sub Button1_Click(sender As Object, e As EventArgs) | |
' create a DataSet from the sample XML data source | |
Dim ds As 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 | |
Dim data As Byte() | |
mailMerge1.SaveDocumentToMemory(data, | |
TXTextControl.BinaryStreamType.AdobePDF, Nothing) | |
' 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]() | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment