locked
Using iTextSharp and still getting corrupted pdf RRS feed

  • Question

  • User-1874132285 posted

    I am unable to export GridView to PDF

     

            HtmlForm frm = new HtmlForm();
            StringWriter sw = new StringWriter();
            HtmlTextWriter hTextWriter = new HtmlTextWriter(sw);
           GridView1.Parent.Controls.Add(frm);
            frm.Attributes["runat"] = "server";
            frm.Controls.Add(GridView1);
            try
            {
                frm.RenderControl(hTextWriter);
            }
            catch (Exception)
            {
    
            } 
            
            Document Doc = new Document();
            Doc.Open();
            StringReader sr = new StringReader(sw.ToString());
            Response.AddHeader("content-disposition", attachment;filename=Export.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/pdf";
            HTMLWorker HtmlParser = new HTMLWorker(Doc);
            HtmlParser.Parse(sr);
            Doc.Close();
            Response.Write(Doc);
            Response.End();
    

     

    The error is "Adobe Reader cannot open the pdf either it is corrupted or not supported type . . . ." 

    Tuesday, April 26, 2011 8:31 AM

Answers

All replies

  • User-1874132285 posted

    Is there anyone who can help me . . ???It's for learning purpose guys.

    Wednesday, April 27, 2011 3:00 AM
  • User1949625403 posted

    hi that problem with itextsharp dll check this post and dowload the attached code and use the dll whatever i used in my code it will solve ur problem

    http://aspdotnet-suresh.blogspot.com/2011/04/how-to-export-gridview-data-to-pdf.html

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 27, 2011 3:19 AM
  • User-1874132285 posted

    Hi thanks for reply but I am getting this error . . 

    RegisterForEventValidation can only be called during Render();

    Wednesday, April 27, 2011 8:31 AM
  • User1949625403 posted

    hi can u please check my post clearly i explained clearly how to solve that problem registerforeventvalidation also in post

    Wednesday, April 27, 2011 11:33 AM
  • User-1874132285 posted

    hi can u please check my post clearly i explained clearly how to solve that problem registerforeventvalidation also in post

    ]

     

    Ok, thanks I got it . . . . . It helped me a lot, thanks to you

    Wednesday, April 27, 2011 1:27 PM