locked
itextsharp cannot output javascript google chart RRS feed

  • Question

  • User-775831949 posted

    I have a page with Gridview and javascript google chart.

    I used iTextsharp to output whole page as pdf and is successful.

    However, only Gridview is there in the pdf and not the google chart.

    Any recommendation as to what I can do ? Thanks

    Monday, December 8, 2014 12:30 AM

Answers

  • User-821857111 posted

    iTextSharp has a fairly rudimentary HTML parser which is capable of converting HTML into PDF content, but it cannot interpret Javascript. If you want to include a chart in your PDF, you will probably have to look for an alternative charting library. The built-in .NET charts render as images, so they can be included in a PDF easily. 

    http://www.mikesdotnetting.com/article/115/microsoft-chart-controls-to-pdf-with-itextsharp-and-asp-net-mvc

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 10, 2014 8:59 AM
  • User-775831949 posted

    Thanks a lot indeed.

    I am using this to output to pdf. I found it cannot output the MsChart on that page.
    It is linked to a sqldatabase. Now it output a blank pdf. Any rescue ? If I point it to print another aspx page with simple text there is no problem.

    Seems Ms Chart cannot be stored into str to be parsed ? Or is it due to the fact that it has to run the database first ?

    Thanks

     Server.Execute("A06_MsChart.aspx", strWriter)
            strHtml = strWriter.ToString()

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 11, 2014 7:44 AM

All replies

  • User-821857111 posted

    iTextSharp has a fairly rudimentary HTML parser which is capable of converting HTML into PDF content, but it cannot interpret Javascript. If you want to include a chart in your PDF, you will probably have to look for an alternative charting library. The built-in .NET charts render as images, so they can be included in a PDF easily. 

    http://www.mikesdotnetting.com/article/115/microsoft-chart-controls-to-pdf-with-itextsharp-and-asp-net-mvc

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 10, 2014 8:59 AM
  • User-775831949 posted

    Thanks a lot indeed.

    I am using this to output to pdf. I found it cannot output the MsChart on that page.
    It is linked to a sqldatabase. Now it output a blank pdf. Any rescue ? If I point it to print another aspx page with simple text there is no problem.

    Seems Ms Chart cannot be stored into str to be parsed ? Or is it due to the fact that it has to run the database first ?

    Thanks

     Server.Execute("A06_MsChart.aspx", strWriter)
            strHtml = strWriter.ToString()

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 11, 2014 7:44 AM
  • User-821857111 posted

    In your shoes, I wouldn't try to convert the HTML to a PDF. I would just generate a PDF using the standard iTextSharp objects like PdfPTable and your chart image.

    Thursday, December 11, 2014 8:01 AM