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

  • SEARCH
  • Home
  • 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 8381257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:39:25+00:00 2026-06-09T16:39:25+00:00

i am trying to export my HTML page to PDF using iTextSharp lib. firstly

  • 0

i am trying to export my HTML page to PDF using iTextSharp lib. firstly i am trying to print table which is in my Aspx page.PDF is created successfully but there nothing in PDF.
i am using this code below :

protected void btnExportToPdf_Click(object sender, EventArgs e)
    {

        btnExportToPdf.Visible = false;


        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        exportTable.RenderControl(hw);

        //this.Page.RenderControl(hw);

        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End(); }
  • 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-09T16:39:27+00:00Added an answer on June 9, 2026 at 4:39 pm

    Now I’m not too seasoned, but the problem to me looks like you are never actually writing the strings to the file. I see a few different string objects you initialize, and I see you adding the HTML to it, but I never see you actually write them to the PDF. This is my usual process for parsing HTML to PDF, maybe you can look at it, and see what you are missing.

    System.Text.StringBuilder store = new System.Text.StringBuilder();
    string line;
    
         while ((line = htmlReader.ReadLine()) != null)
         {
           store.Append(line + Environment.NewLine);
         }
    
    string html = store.ToString();
    FileStream stream = new FileStream(newFileName, FileMode.Create, FileAccess.Write);
    Document document = new Document(PageSize.LETTER, 15, 15, 35, 25);
    PdfWriter writer = PdfWriter.GetInstance(document, stream);
    document.Open();
    System.Collections.Generic.List<IElement> htmlarraylist = new List<IElement>(HTMLWorker.ParseToList(new StringReader(html), new StyleSheet()));
    
         foreach (IElement element in htmlarraylist)
         {
            document.Add(element);
         }
    
    document.Close();
    

    That was what jumped out to me at least, was the fact that it doesn’t look like you actually write the generated text to the PDF. I hope this helps.

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

Sidebar

Related Questions

I am trying to export an html table to excel using JavaScript. However I
I trying to export an HTML table named Table that is dynamically binded to
I'm trying to create a page using ASP.NET MVC 2 which shows two things:
I am trying to export an HTML table to excel but I cannot set
I'm getting the following error when trying to produce an HTML page using Jade.
I'm trying to use FOP to export a PDF with UTF-8 characters, preferably without
I am trying to export some data from a SQL Express table to Access
I'm trying to export a Crystal Report to an HTML file, but when I
I am trying to export a list of table to comma-separated value(CSV) .but not
I am trying to capture the contents of my php page using output buffering:

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.