locked
export a aspx page to pdf RRS feed

  • Question

  • User63199524 posted

    I tried eporting a Aspx page to pdf. it gives the error. Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'.It throws the error here htmlparser.Parse(sr); I have checked the internet for solution, but there seems to be none solving my problem. Somebody please help me out

    Monday, March 16, 2015 11:26 AM

Answers

  • User281315223 posted

    Do you have an example of the code or markup that you are trying to convert? iTextSharp can be very sensitive with regards to any syntax errors or unexpected content and may be prone to throwing errors like this. You'll also want to ensure that you are using the correct parser, as I believe that the original HTML parser was deprecated for the XML Worker instead.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 16, 2015 11:43 AM

All replies

  • User281315223 posted

    Do you have an example of the code or markup that you are trying to convert? iTextSharp can be very sensitive with regards to any syntax errors or unexpected content and may be prone to throwing errors like this. You'll also want to ensure that you are using the correct parser, as I believe that the original HTML parser was deprecated for the XML Worker instead.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 16, 2015 11:43 AM
  • User63199524 posted

    Thank you for ur fast reply Rion :) Please check my code .

    protected void Button2_Click(object sender, EventArgs e)
    {
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    this.Page.DataBind();
    this.Page.RenderControl(hw);
    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); // Here i am getting error like this Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'.

    pdfDoc.Close();

    Response.Write(pdfDoc);
    Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    /* Verifies that the control is rendered */
    }
    }

    Monday, March 16, 2015 12:04 PM