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 8073099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:13:45+00:00 2026-06-05T14:13:45+00:00

Converting a generated html page to pdf using iTextSharp, I cannot get the table

  • 0

Converting a generated html page to pdf using iTextSharp, I cannot get the table created from the asp:DataGrid to show up in the PDF. The page’s HTML output for the datagrid looks like this:

<p>Purchases:</p>
    <table rules="all" id="dg_Purchase" style="font-size: smaller; border-collapse: collapse;" border="1" cellspacing="0">
    <tbody><tr>
        <td>Lot #</td>
        <td>&nbsp;</td>
        <td>Title</td>
        <td align="right">Price</td>
        <td align="right">Buyer's Premium</td>
        <td align="right">Tax</td>
        <td align="right">Sub Total</td>
    </tr><tr>
        <td>118</td>
        <td><input id="dg_Purchase_ctl02_CheckBox1" name="dg_Purchase$ctl02$CheckBox1" type="checkbox"></td>
        <td>Yih-Wen Kuo (1959, Taiwan)</td>
        <td align="right">$1,900.00</td>
        <td align="right">$332.50</td>
        <td align="right">$0.00</td>
        <td align="right">$2,232.50</td>
    </tr><tr>
        <td>119</td>
        <td><input id="dg_Purchase_ctl03_CheckBox1" name="dg_Purchase$ctl03$CheckBox1" type="checkbox"></td>
        <td>Yih-Wen Kuo (1959, Taiwan)</td>
        <td align="right">$1,800.00</td>
        <td align="right">$315.00</td>
        <td align="right">$0.00</td>
        <td align="right">$2,115.00</td>
    </tr>
</tbody></table>

<p>Payments:</p>
    <table rules="all" id="dg_Payment" style="font-size: smaller; border-collapse: collapse;" border="1" cellspacing="0">
    <tbody><tr>
        <td style="width: 120px;">Payment Method</td>
        <td>Date</td>
        <td align="right">Amount&nbsp;&nbsp;</td>
    </tr><tr>
        <td>Total</td>
        <td>&nbsp;</td>
        <td align="right">$0.00</td>
    </tr>
</tbody></table>

When the HTML page is viewed, the table looks exactly how it should. But when I generate the PDF, the table (or rather, everything within the table) is not shown. Only the border is visible, pretty much being just a 2 px straight line for each table.

So in my normal script, after the entire page has loaded, the very last thing I do is:

    StringWriter stringWriter = new StringWriter();
    HtmlTextWriter writer = new HtmlTextWriter(stringWriter);
    Render(writer);

The functions for iTextSharp are below:

protected override void Render(HtmlTextWriter writer)
{
    MemoryStream mem = new MemoryStream();
    StreamWriter twr = new StreamWriter(mem);
    HtmlTextWriter myWriter = new HtmlTextWriter(twr);
    base.Render(myWriter);
    myWriter.Flush();
    myWriter.Dispose();
    StreamReader strmRdr = new StreamReader(mem);
    strmRdr.BaseStream.Position = 0;
    string pageContent = strmRdr.ReadToEnd();
    strmRdr.Dispose();
    mem.Dispose();
    writer.Write(pageContent);
    CreatePDFDocument(pageContent);
}

public void CreatePDFDocument(string strHtml)
{

    string strFileName = HttpContext.Current.Server.MapPath("test.pdf");
    // step 1: creation of a document-object
    Document document = new Document();
    // step 2:
    // we create a writer that listens to the document
    PdfWriter.GetInstance(document, new FileStream(strFileName, FileMode.Create));
    StringReader se = new StringReader(strHtml);
    HTMLWorker obj = new HTMLWorker(document);
    document.Open();
    obj.Parse(se);
    document.Close();
    ShowPdf(strFileName);
}

public void ShowPdf(string strFileName)
{
    Response.ClearContent();
    Response.ClearHeaders();
    Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
    Response.ContentType = "application/pdf";
    Response.WriteFile(strFileName);
    Response.Flush();
    Response.Clear();
}

Again, everything on the page that is set programatically does show up in the PDF EXCEPT for the datagrid. Going off the borders, it appears that it is not a width issue. It just appears to be empty, is all. Any help would be greatly appreciated.

  • 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-05T14:13:48+00:00Added an answer on June 5, 2026 at 2:13 pm

    Well I couldn’t find rhyme or reason as to why this would not work, so I went another route. I decided to make the page that generates the HTML code a secondary page, and have the one generating the PDF just reference it. I ended up with:

    String address = "http://address.com/admin/Invoice2.aspx?sale_id=" + sale_id + "&bidder_number=" + bidder_number;
    
    using (WebClient wc = new WebClient())
    {
        string content = wc.DownloadString(address);
        CreatePDFDocument(content);
    }
    

    in my page load method, and just kept the other 2 functions:

    public void CreatePDFDocument(string strHtml)
    {
    
        string strFileName = HttpContext.Current.Server.MapPath("invoice.pdf");
        // step 1: creation of a document-object
        Document document = new Document();
        // step 2:
        // we create a writer that listens to the document
        PdfWriter.GetInstance(document, new FileStream(strFileName, FileMode.Create));
        StringReader se = new StringReader(strHtml);
        HTMLWorker obj = new HTMLWorker(document);
        document.Open();
        obj.Parse(se);
        document.Close();
        ShowPdf(strFileName);
    }
    
    public void ShowPdf(string strFileName)
    {
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
        Response.ContentType = "application/pdf";
        Response.WriteFile(strFileName);
        Response.Flush();
        Response.Clear();
    }
    

    Now I just need to get the styling of the tables to transfer to the PDF and I’ll be good. But that’s another issue.

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

Sidebar

Related Questions

I am converting a script from PHP to ASP.net C#. In PHP, i could
I've noticed that most of the HTML/XML/HAML that gets generated from plugins uses 2
I'm converting some Polish<->English dictionaries from RTF to HTML. The Polish special characters are
I have the following image list on an html page that I am converting
I have a service that extracting html code from an URL, converting it to
well i faced i lot of prob converting the html data on page to
I have a problem when converting a static html table to one which is
I am converting a XML to HTML using XSLT. The output of should have
Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
I'm converting a large, multi-project CVS repository into Subversion using cvs2svn. It's working really

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.