Export to PDF from Gridview

Unsentethenue

New Member
I have done the export to PDF from gridview using iTextSharp. Since the gridview columns are more the columns in PDF is not aligned and it is so small. I tried writing styles in both codebehind and .aspx page. But the size is not changing.// .aspx Page\[code\] <asp:GridView ID="grdResult" runat="server" AutoGenerateColumns="true" Width="100%" CellPadding="3" CellSpacing="3" Font-Size="10pt"> <HeaderStyle Font-Bold="true" Width="250px" /> </asp:GridView>\[/code\]// .cs Page\[code\]Response.ContentType = "application/pdf";Response.AddHeader("content-disposition", "attachment;filename=MARGEmployees.pdf");Response.Cache.SetCacheability(HttpCacheability.NoCache);StringWriter sw = new StringWriter();HtmlTextWriter hw = new HtmlTextWriter(sw);HtmlForm frm = new HtmlForm();grdResult.Parent.Controls.Add(frm);frm.Attributes["runat"] = "server";frm.Controls.Add(grdResult);frm.RenderControl(hw);grdResult.HeaderRow.Style.Add("width", "15%");grdResult.HeaderRow.Style.Add("font-size", "10px");grdResult.Style.Add("font-family", "Tahoma");grdResult.Style.Add("font-size", "8px");StringReader sr = new StringReader(sw.ToString());Document pdfDoc = new Document(PageSize.A4, 7f, 7f, 7f, 0f);HTMLWorker htmlparser = new HTMLWorker(pdfDoc);PdfWriter.GetInstance(pdfDoc, Response.OutputStream);pdfDoc.Open();htmlparser.Parse(sr);pdfDoc.Close();Response.Write(pdfDoc);Response.End();\[/code\]Help me on this.
 
Back
Top