convert html table into pdf in asp.net RRS feed

  • Question

  • User1488676540 posted

    I have a html code with multiple tables inside it and multiple tr and td tags inside each table..

    I want to convert the whole table into pdf 

    how to do this in asp.net??

    can i directly convert??

    I dont want to use any paid tool (any free tool is ok)..

    Saturday, March 15, 2014 2:52 AM


All replies

  • User-492460945 posted

    Try using this..

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=file.pdf");
            Response.Charset = "";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            Response.BufferOutput = true;

    where str is your html string.

    Saturday, March 15, 2014 4:35 AM
  • User281315223 posted

    Answers may depend on your actual needs so I'll provide a few suggestions below and let you dig through them.

    Consider iTextSharp

    You will have to use iTextSharp (or another third-part PDF library) to actually generate the PDF itself, however you can call the necessary code to generate it within any method that you would like (including your a Button-Click event).

    I have always found iTextSharp very easy to use and there is a good bit of documentation, tutorials and other resources online primarily due to the popularity of the library.

    Mikesdotnetting has a great intro to iTextSharp on his blog post here that I would recommend checking out as well as some of the following articles to get you started :

    If you need this for "Reporting"

    Obviously with most questions of this nature, there is not going to be any "best" answer as Reporting is one of those highly subjective topics that depends on your requirements and personal preferences.

    I don't have a ton of experience with working with open-source reporting tools (as the commerical options have always been available). However, there are lots of them available if you look around : 

    I would highly encourage downloading and playing around with each of these and determining the one that you like the most and is the easiest to work with. As you can see there are tons of choices out there and these were just a few of the more popular options.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 15, 2014 10:10 AM