ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Show footer in PDF file using iTextSharp in ASP.Net<p>Hi <a class="username" rel="smile">smile</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML </strong></span></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;ContactName&#34; HeaderText=&#34;Contact Name&#34; /&gt; &lt;asp:BoundField DataField=&#34;City&#34; HeaderText=&#34;City&#34; /&gt; &lt;asp:BoundField DataField=&#34;Country&#34; HeaderText=&#34;Country&#34; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;br /&gt; &lt;asp:Button ID=&#34;btnExport&#34; runat=&#34;server&#34; Text=&#34;Export To PDF&#34; OnClick=&#34;ExportToPDF&#34; /&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.IO; using System.Data; using System.Data.SqlClient; using System.Configuration; using iTextSharp.text; using iTextSharp.text.html.simpleparser; using iTextSharp.text.pdf;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.BindGrid(); } } private void BindGrid() { string strConnString = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(strConnString)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT TOP 10* FROM Customers&#34;)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; using (DataTable dt = new DataTable()) { sda.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } } } } } protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; this.BindGrid(); } protected void ExportToPDF(object sender, EventArgs e) { using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { GridView1.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A2, 20, 20, 25, 25); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter write = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); write.PageEvent = new Footer(); pdfDoc.Close(); Response.ContentType = &#34;application/pdf&#34;; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment;filename=GridViewExport.pdf&#34;); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfDoc); Response.End(); } } } public partial class Footer : PdfPageEventHelper { public override void OnEndPage(PdfWriter writer, Document doc) { Paragraph footer = new Paragraph(&#34;Computer Generated Report&#34;, FontFactory.GetFont(FontFactory.TIMES_BOLD, 15, iTextSharp.text.Font.BOLD)); footer.Alignment = Element.ALIGN_MIDDLE; PdfPTable footerTbl = new PdfPTable(1); footerTbl.TotalWidth = 250; footerTbl.HorizontalAlignment = Element.ALIGN_LEFT; footerTbl.AddCell(footer); footerTbl.WriteSelectedRows(0, -1, 400, 150, writer.DirectContent); } } public override void VerifyRenderingInServerForm(Control control) { /* Verifies that the control is rendered */ }</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><span style="text-decoration: underline;"><strong><img src="https://imgur.com/uK7Fkl6.jpg" alt="" width="353" height="508" /></strong></span></p>https://www.aspforums.net:443/Threads/299086/Show-footer-in-PDF-file-using-iTextSharp-in-ASPNet/https://www.aspforums.net:443/Threads/299086/Show-footer-in-PDF-file-using-iTextSharp-in-ASPNet/Tue, 18 Sep 2018 01:08:11 GMT