Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The error is Unable to cast object of type "'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'". Plese dont duplicate i couldnot find the solution.
Please Help



C#
Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        pnlPerson.RenderControl(hw);
        gridstudentnotes.DataBind();

        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();
Posted
Updated 22-Mar-17 0:01am
v2
Comments
Sergey Alexandrovich Kryukov 16-Mar-15 1:36am    
In what line? Whatever it is, of course you cannot cast it; what could possibly be unclear in this error message?
—SA
[no name] 16-Mar-15 1:50am    
I assume it's occurring in non-user-code in htmlparser.Parse(sr); because there's nowhere a visible cast. Maybe some sort of configuration mistake, but I have no experience with iTextSharp.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900