Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:59:30+00:00 2026-06-04T12:59:30+00:00

i am trying to read a html file and convert it to pdf using

  • 0

i am trying to read a html file and convert it to pdf using itexsharp and send it as attachment by email :

this is the client side code

<form id="form1" runat="server">
<div>
<img alt="" src="C:\Users\Intern\Documents\Visual Studio  2008\Projects\highChart\highChart\images\279.gif" id="myImg" />

</div>
</form>

server side code

 Imports iTextSharp
 Imports iTextSharp.text.pdf
 Imports iTextSharp.text
 Imports System
 Imports System.Text
 Imports System.IO
 Imports System.Net.Mail
 Imports System.Net
 Imports iTextSharp.text.html.simpleparser

 Partial Public Class imagePdf
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Response.ContentType = "application/pdf"
    Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf")
    Response.Cache.SetCacheability(HttpCacheability.NoCache)
    Dim sw As New StringWriter()
    Dim hw As New HtmlTextWriter(sw)
    Me.Page.RenderControl(hw)

    Dim sr As New StringReader(sw.ToString())
    Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 100.0F, 0.0F)
    Dim htmlparser As New HTMLWorker(pdfDoc)
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
    pdfDoc.Open()
    htmlparser.Parse(sr)
    pdfDoc.Close()
    Response.Write(pdfDoc)
    Response.[End]()

    Dim file As (( i don't know what to add here ))
    Dim message As New MailMessage()
    message.From = New MailAddress("testApp@somewhereelse.com")
    message.To.Add(New MailAddress("anotheraddres84@hotmail.com"))
    message.Subject = "pdf "
    message.Body = "pdf attached "
    Dim data As New Attachment(File)
    message.Attachments.Add(data)

    Dim client As New SmtpClient()
    client.Host = "smtp.gmail.com"
    client.Credentials = New NetworkCredential("email", "password")
    client.EnableSsl = True
    client.Port = 587
    client.Send(message)
End Sub

End Class

Each part of this code works fine, i.e. the pdf works, email is fine but how can I use the pdf file as my attached file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:59:32+00:00Added an answer on June 4, 2026 at 12:59 pm

    Store PDF as a file, and then add it to the message by using the MailMessage.Attachments property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read http://free.freeshoutcast.com:39072/7.html this page, I tried this code, <?php function curl_get_file_contents($URL)
I am trying to read a html file which is a plain page with
I just read about HTML 5's WebSocket interface. How can I start trying this?
I am trying to read the content of a PHP / HTML file on
I am trying to read a 12MB+ file which has a large HTML table
Similar to this question , I am trying to load an HTML file into
I'm trying to obtain data using regular expressions from a html file, by implementing
I'm trying to include a html file using the following syntax: <%@ include file=path/to/file.html
I'm trying to read a file with the HTML5 FileReader API. This works fine
I'm trying to open an .html file as one big long string. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.