1

I am trying to Export Repeater Into PDF but Its Giving Error . On click of Button I am Exporting Repeater Data Into PDF.when i parse Object using htmlparser.Parse(sr) It will Give An exception of type 'System.InvalidCastException' occurred in itextsharp.dll but was not handled in user code

Additional information: Unable to cast object of type 'iTextSharp.text.html.simpleparser.IncTable' to type 'iTextSharp.text.IElement'.

  Response.ContentType = "application/pdf"
    Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf")
    Response.Cache.SetCacheability(HttpCacheability.NoCache)
    Dim sw As New StringWriter()
    Dim hw As New HtmlTextWriter(sw)
    repeater1.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()
  • As explained *many, many, many* times before on Stack Overflow, in answer to *many, many, many* identical questions: `HTMLWorker` **is no longer supported.** Read the [intro of the HTML to PDF tutorial](https://developers.itextpdf.com/content/itext-7-converting-html-pdf-pdfhtml) to learn about the history of HTML to PDF conversion with iText(Sharp). – Bruno Lowagie Nov 15 '17 at 06:28
  • See the comments of [C# iTextSharp How to convert a piece of HTML into PDF](https://stackoverflow.com/questions/46827052), [Itextsharp HTML Table Conversion](https://stackoverflow.com/questions/46936960), [How to display chinese characters in PDF using ITextSharp in c#?](https://stackoverflow.com/questions/47075049), [C# iTextSharp How to convert a piece of HTML into PDF](https://stackoverflow.com/questions/46827052), and many other instances where we explained that `HTMLWorker` will cause nothing but frustration! **Stop using it! Upgrade to iText 7 + pdfHTML!** – Bruno Lowagie Nov 15 '17 at 06:35
  • please provide better option for export repeater data into PDF. if possible provide source code with reference . – Sunny Raval Nov 15 '17 at 07:03
  • Stack Overflow is not a forum where you can ask people to do your homework. I will vote to close your question because of your comment. Asking "provide source code" isn't appreciated here. – Bruno Lowagie Nov 15 '17 at 07:11
  • i just telling that provide better solution – Sunny Raval Nov 15 '17 at 08:32
  • I just told: try iText 7 + pdfHTML. Read about it in the [HTML to PDF tutorial](https://developers.itextpdf.com/content/itext-7-converting-html-pdf-pdfhtml). You mentioning `Repeater` is irrelevant. You are essentially converting HTML to PDF. So don't confuse people by asking for "better option for export repeater data." – Bruno Lowagie Nov 15 '17 at 10:49

0 Answers0