Click here to Skip to main content
15,886,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

Hi,

You did not add a new Page to the document

C#
pdfdoc.newPage();
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900