When executing the following code no errors are thrown but the pdf generated as an attachment is blank and its file size is 0k.
Edit:
Dim page As Page = New Page()
Dim form As HtmlForm = New HtmlForm()
page.Controls.Add(form)
Dim bpa As UserControl_BpaReceipt = page.LoadControl("~/UserControl/BpaReceipt.ascx")
bpa._thisCart = _thisCart
form.Controls.Add(bpa)
Dim writer As StringWriter = New StringWriter()
Me.Server.Execute(page, writer, False)
End Edit:
Dim bytes = Encoding.UTF8.GetBytes(writer.ToString())
Dim input As MemoryStream = New MemoryStream(bytes)
Dim output As MemoryStream = New MemoryStream()
''//Dim reader As TextReader = New StringReader(writer.ToString())
Dim doc As Document = New Document(PageSize.A4.Rotate, 30, 30, 30, 30)
Dim pdfWriter As PdfWriter = pdfWriter.GetInstance(doc, output)
doc.Open()
XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, doc, input, Nothing)
email.Attachments.Add(New Attachment(output, "Quote.pdf", "application/pdf"))
Dim smtp As New SmtpClient()
smtp.Credentials = New System.Net.NetworkCredential(System.Web.Configuration.WebConfigurationManager.AppSettings("SMTPUser").ToString(), System.Web.Configuration.WebConfigurationManager.AppSettings("SMTPPassword").ToString())
smtp.Send(email)
doc.Close()
I am very new to this process and any help would be greatly appreciated. Also, to clarify if I output to a file instead of a stream the html in the writer.toString() is outputted as expected.
I appreciate any thoughts on the matter.
Thanks,
Edit:
Dim page As Page = New Page()
Dim form As HtmlForm = New HtmlForm()
page.Controls.Add(form)
Dim bpa As UserControl_BpaReceipt = page.LoadControl("~/UserControl/BpaReceipt.ascx")
bpa._thisCart = _thisCart
form.Controls.Add(bpa)
Dim writer As StringWriter = New StringWriter()
Me.Server.Execute(page, writer, False)
email.IsBodyHtml = True
If (toValues.Value.Contains(";")) Then
Dim toArray = toValues.Value.Split(";")
For Each value In toArray
email.To.Add(value)
Next
Else
email.To.Add(toValues.Value.ToString())
End If
email.Subject = txtSubject.Text
email.Body = "<br /><br /><br />" & writer.ToString()
email.From = New MailAddress("webadmin@managemobility.com")
Dim bytes = Encoding.UTF8.GetBytes(writer.ToString())
Dim input As MemoryStream = New MemoryStream(bytes)
Dim output As MemoryStream = New MemoryStream()
''//Dim reader As TextReader = New StringReader(writer.ToString())
Dim doc As Document = New Document(PageSize.A4.Rotate, 30, 30, 30, 30)
Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(doc, output)
pdfWrite.CloseStream = False
doc.Open()
XMLWorkerHelper.GetInstance().ParseXHtml(pdfWrite, doc, input, Nothing)
doc.Close()
email.Attachments.Add(New Attachment(output, "Quote.pdf", "application/pdf"))
Dim smtp As New SmtpClient()
smtp.Credentials = New System.Net.NetworkCredential(System.Web.Configuration.WebConfigurationManager.AppSettings("SMTPUser").ToString(), System.Web.Configuration.WebConfigurationManager.AppSettings("SMTPPassword").ToString())
smtp.Send(email)
''//doc.Close()
I edited the the code to reflect your suggestions and I'm afraid I still received the same output an empty pdf 0kb. Thank you so much for your suggestions I to am quite vexed by this issue also and truly appreciate the suggestions.