0

Code :

protected void btnExportPDF_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    C1GridView1_listview.AllowPaging = false;
    C1GridView1_listview.DataBind();
    C1GridView1_listview.RenderControl(hw);
    C1GridView1_listview.HeaderRow.Style.Add("width", "15%");
    C1GridView1_listview.HeaderRow.Style.Add("font-size", "10px");
    C1GridView1_listview.Style.Add("text-decoration", "none");
    C1GridView1_listview.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
    C1GridView1_listview.Style.Add("font-size", "8px");
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);//this is error line
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
}

Error:

Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'.

How can I fix this error?

Damith
  • 62,401
  • 13
  • 102
  • 153
jintha arun
  • 31
  • 1
  • 10
  • i am used c1gridview but does not export to pdf?why? – jintha arun Jun 28 '12 at 18:12
  • 1
    [See here](http://stackoverflow.com/questions/8414637/itextsharp-htmlworker-parsehtml-tablestyle-and-pdfstamper) and [here](http://www.codedigest.com/Articles/ASPNET/344_Export_to_PDF_file_in_ASPNet-Gridview_to_PDF_ASPX_Page_Content_to_PDF.aspx) if it helps. – Estefany Velez Jun 28 '12 at 18:40
  • Try checking your image html links - http://am22tech.com/s/22/Blogs/post/2011/09/28/HTML-To-PDF-using-iTextSharp.aspx (converted more appropriately to comment) – Tom Jun 28 '12 at 18:42
  • I AM USED C1GRIDVIEW HOW CAN I GET THE PDFEXPORT? – jintha arun Jun 28 '12 at 19:16
  • Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'. SAME ERROR CAME IN THIS LINE/// htmlparser.Parse(sr); – jintha arun Jun 28 '12 at 19:19
  • OTHERWISE HOW CAN I C1GRIDVIEW VALUE BIND THE C1REPORTVIEWER(COMPONENT ONE) – jintha arun Jun 28 '12 at 19:26

0 Answers0