Click here to Skip to main content
14,545,215 members
Rate this:
Please Sign up or sign in to vote.
See more:
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
GridView1.AllowPaging = false;

this.DataBind();
GridView1.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());
Document pdfdoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfdoc);
pdfdoc.PageCount = 1;
PdfWriter.GetInstance(pdfdoc, Response.OutputStream);

pdfdoc.Open();
htmlparser.Parse(sr);
pdfdoc.Close();

Response.ContentType = "Application/pdf";
Response.AddHeader("content-disposition", "attachemnt;filename=FileName.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Write(pdfdoc);

Response.End();

}
}
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,

You did not add a new Page to the document

pdfdoc.newPage();
   
Comments
Shrikesh_kale 16-Feb-15 7:14am
   
i tried but it is not working give same error
Suvabrata Roy 16-Feb-15 7:39am
   
Go through it http://www.codeproject.com/Questions/815062/Problem-in-Export-Repeater-data-to-pdf-in-asp-net

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100