I've change a bit the code to suit my needs.
protected void imgBtnPrint_Click(object sender, ImageClickEventArgs e)
{
Document doc = new Document(PageSize.A4.Rotate(), 30f, 30f, 30f, 30f);
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
for (int i = 0; i < gvSiriAudit.PageCount; i++)
{
//Set the Page Index.
gvSiriAudit.PageIndex = i;
//Hide Page as not needed in PDF.
gvSiriAudit.PagerSettings.Visible = false;
//Populate the GridView with records for the Page Index.
this.BindGridSiriAudit();
//Render the GridView as HTML and add to PDF.
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
gvSiriAudit.RenderControl(hw);
HTMLWorker htmlparser = new HTMLWorker(doc);
StringReader sr = new StringReader(sw.ToString());
gvSiriAudit.HeaderStyle.ForeColor = System.Drawing.Color.White;
htmlparser.Parse(sr);
}
}
//Add a new Page to PDF document.
doc.NewPage();
}
doc.Close();
Response.ContentType = "Application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=GridviewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(doc);
Response.End();
}