Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created July 21, 2017 16:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bjoerntx/6b453d29c5d20eb93c61d3aec9c11b9c to your computer and use it in GitHub Desktop.
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