protected void ExportToPDF(GridView gvuser, string fileName, bool isLastColVisible, bool isLogo)
{
if (gvuser == null)
return;
if (string.IsNullOrEmpty(fileName))
fileName = "Bucco.pdf";
gvuser = PrepareGridViewForExport(gvuser);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
if (!isLastColVisible)
gvuser.Columns[gvuser.Columns.Count - 1].Visible = false;
//gvuser.RowStyle.Height = 20;
//gvuser.HeaderRow.Style.Add("height", "20px");
gvuser.GridLines = GridLines.Vertical;
gvuser.HeaderStyle.BackColor = System.Drawing.Color.Green;
gvuser.HeaderRow.Style.Add("background", "green");
gvuser.HeaderRow.Style.Add("font-size", "8px");
gvuser.Style.Add("text-decoration", "none");
gvuser.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gvuser.Style.Add("font-size", "6px");
gvuser.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(gvuser);
frm.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
if (isLogo)
{
iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(Server.MapPath("~/App_Themes/buco/images/logo.jpg"));
pdfDoc.Add(gif);
}
pdfDoc.Add(new Paragraph(fileName.Substring(0, fileName.IndexOf('.'))));
pdfDoc.Add(new Paragraph(" "));
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}