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.Exporting HTML and GridView to PDF data showing from 2nd page if more record in ASP.Net<p>Hi <a class="username" rel="ashokpumca"> ashokpumca</a>,</p> <p>Please take reference to below code and correct your code.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;div id=&#34;dvHtml&#34; runat=&#34;server&#34; style=&#34;margin: 0 0 0 0;&#34;&gt; &lt;asp:Button ID=&#34;btn&#34; runat=&#34;server&#34; Text=&#34;Print&#34; OnClick=&#34;ButnPrint_Click&#34; /&gt; &lt;table style=&#34;text-align: left; width: 100%; font-size: 11px; background-color: white&#34; border=&#34;0&#34; cellpadding=&#34;6&#34; cellspacing=&#34;0&#34;&gt; &lt;tr&gt; &lt;td&gt; Report Name : &lt;asp:Label ID=&#34;lblReport&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td&gt; Report Generated At : &lt;asp:Label ID=&#34;lblReptAt&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Report Generated By : &lt;asp:Label ID=&#34;lblReptBy&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td&gt; Machine IP : &lt;asp:Label ID=&#34;lblReptIP&#34; runat=&#34;server&#34; Text=&#34;&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan=&#34;2&#34;&gt; &lt;asp:GridView ID=&#34;gvCustomers&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34; DataKeyNames=&#34;CustomerID&#34; Width=&#34;100%&#34; Font-Size=&#34;9&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;CustomerID&#34; HeaderText=&#34;CustomerID&#34;&gt; &lt;ItemStyle Width=&#34;20px&#34; Height=&#34;25px&#34; /&gt; &lt;/asp:BoundField&gt; &lt;asp:BoundField DataField=&#34;CompanyName&#34; HeaderText=&#34;CompanyName&#34;&gt; &lt;ItemStyle Width=&#34;450px&#34; /&gt; &lt;/asp:BoundField&gt; &lt;asp:BoundField DataField=&#34;ContactName&#34; HeaderText=&#34;ContactName&#34;&gt; &lt;ItemStyle Width=&#34;50&#34; /&gt; &lt;/asp:BoundField&gt; &lt;asp:BoundField DataField=&#34;ContactTitle&#34; HeaderText=&#34;ContactTitle&#34;&gt; &lt;ItemStyle Width=&#34;150px&#34; /&gt; &lt;/asp:BoundField&gt; &lt;asp:BoundField DataField=&#34;Address&#34; HeaderText=&#34;Address&#34;&gt; &lt;ItemStyle Width=&#34;100px&#34; /&gt; &lt;/asp:BoundField&gt; &lt;asp:BoundField DataField=&#34;City&#34; HeaderText=&#34;City&#34;&gt; &lt;ItemStyle Width=&#34;350px&#34; /&gt; &lt;/asp:BoundField&gt; &lt;/Columns&gt; &lt;HeaderStyle Font-Bold=&#34;True&#34; Font-Names=&#34;Trebuchet MS&#34; Font-Size=&#34;10&#34; /&gt; &lt;/asp:GridView&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data.SqlClient; using System.Data; using System.Configuration; using System.IO; using iTextSharp.text; using iTextSharp.text.html.simpleparser; using iTextSharp.text.pdf; using System.Web.UI.WebControls;</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 (!this.IsPostBack) { string conString = ConfigurationManager.ConnectionStrings[&#34;conString&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(conString)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT * FROM Customers&#34;, con)) { using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); da.Fill(dt); gvCustomers.DataSource = dt; gvCustomers.DataBind(); } } } } } protected void ButnPrint_Click(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; Response.ContentType = &#34;application/pdf&#34;; &nbsp;&nbsp;&nbsp; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment;filename= report.pdf&#34;); &nbsp;&nbsp;&nbsp; Response.Cache.SetCacheability(HttpCacheability.NoCache); &nbsp;&nbsp;&nbsp; StringWriter sw = new StringWriter(); &nbsp;&nbsp;&nbsp; HtmlTextWriter hw = new HtmlTextWriter(sw); &nbsp;&nbsp;&nbsp; Label label = new Label(); &nbsp;&nbsp;&nbsp; gvCustomers.Parent.Controls.Add(label); &nbsp;&nbsp;&nbsp; label.Controls.Add(gvCustomers); &nbsp;&nbsp;&nbsp; dvHtml.RenderControl(hw); &nbsp;&nbsp;&nbsp; StringReader sr = new StringReader(sw.ToString()); &nbsp;&nbsp;&nbsp; Document pdfDoc = new Document(PageSize.LEGAL, 5, 5, 5, 5); &nbsp;&nbsp;&nbsp; HTMLWorker htmlparser = new HTMLWorker(pdfDoc); &nbsp;&nbsp;&nbsp; PdfWriter.GetInstance(pdfDoc, Response.OutputStream); &nbsp;&nbsp;&nbsp; pdfDoc.Open(); &nbsp;&nbsp;&nbsp; htmlparser.Parse(sr); &nbsp;&nbsp;&nbsp; pdfDoc.Close(); &nbsp;&nbsp;&nbsp; Response.Write(pdfDoc); &nbsp;&nbsp;&nbsp; Response.End(); } public override void VerifyRenderingInServerForm(Control control) { /* Verifies that the control is rendered */ }</pre>https://www.aspforums.net:443/Threads/426089/Exporting-HTML-and-GridView-to-PDF-data-showing-from-2nd-page-if-more-record-in-ASPNet/https://www.aspforums.net:443/Threads/426089/Exporting-HTML-and-GridView-to-PDF-data-showing-from-2nd-page-if-more-record-in-ASPNet/Fri, 29 Jun 2018 03:00:43 GMT