Mohammad Aman

Mohammad Aman

  • Tech Writer
  • 327
  • 72.4k

generated pdf download and send to a email id using iTextSha

Mar 3 2016 4:53 AM
I am using iTextSharp to generate pdf file but i want to send that pdf to a email address. How can send generated pdf file to email using my given code. Please help me.
How to send pdf in email using MailSender() function.
Using sw As New StringWriter()
Using hw As New HtmlTextWriter(sw)
repeaterName.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 50.0F, 50.0F, 40.0F, 50.0F)
Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr)
pdfDoc.Close()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=" + ViewState("BillNo").ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Write(pdfDoc)
Response.End()
End Using
End Using

Answers (3)