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.Display Column Sum while generating PDF using C# in Windows Application<p>Hi <a class="username" rel="smile"> smile</a>,</p> <p>Refer below sample.</p> <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.IO; using iTextSharp.text; 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">private void Form1_Load(object sender, EventArgs e) { DataTable dt = GetData(); this.dataGridView1.DataSource = dt; } private DataTable GetData() { SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(@&#34;DECLARE @DynamicPivotQuery AS NVARCHAR(MAX) DECLARE @cols NVARCHAR(MAX) DECLARE @qry NVARCHAR(4000) SELECT @cols= ISNULL(@cols + &#39;,&#39;,&#39;&#39;) + QUOTENAME(Head) FROM (SELECT DISTINCT Head FROM tblFeesGenerate WHERE Head &lt;&gt; 0 AND Month=&#39;06-Jun&#39;) AS Head IF(@cols IS NOT NULL AND @cols &lt;&gt; &#39;[0]&#39;) SET @qry = N&#39;SELECT distinct AdmissionNo,Month,Fees, &#39; + @cols + &#39; FROM (SELECT AdmissionNo,Month,Fees,Head,Price FROM tblFeesGenerate WHERE Month=&#39;&#39;06-Jun&#39;&#39;) p PIVOT (MAX(Price) FOR Head IN (&#39; + @cols + &#39;)) AS Pvt&#39; ELSE BEGIN SET @qry = &#39;SELECT DISTINCT AdmissionNo,Month,Fees FROM tblFeesGenerate WHERE Month=&#39;&#39;06-Jun&#39;&#39;&#39; END EXEC sp_executesql @qry&#34;, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); return dt; } private void btnGP_Click(object sender, EventArgs e) { DataTable sTable = GetData(); DataTable dt1 = new DataTable(); dt1.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;Amount&#34;, typeof(int)) }); string pdfpath = @&#34;C:\Users\anand\Desktop\Test\\&#34;; if (!Directory.Exists(pdfpath)) { Directory.CreateDirectory(pdfpath); } string folderPath = @&#34;C:\Users\anand\Desktop\Test\\&#34;; FileStream stream = new FileStream(folderPath + &#34;DataGridViewExport.pdf&#34;, FileMode.Create); Document doc = new Document(); PdfWriter.GetInstance(doc, stream); doc.Open(); for (int i = 0; i &lt; sTable.Rows.Count; i++) { dt1.Rows.Clear(); PdfPTable table = new PdfPTable(3); table.TotalWidth = 500f; table.LockedWidth = true; float[] widths = new float[] { 0.05f, 0.1f, 0.1f }; table.SetWidths(widths); table.DefaultCell.Padding = 7f; table.HorizontalAlignment = Element.ALIGN_CENTER; table.SpacingBefore = 5f; PdfPCell headerb = new PdfPCell(new Phrase(&#34;Fees Details&#34;, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12))); headerb.Indent = 10; headerb.HorizontalAlignment = 1; headerb.Padding = 10f; headerb.Colspan = 4; table.AddCell(headerb); table.AddCell(new Phrase(&#34;S.No.&#34;, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12))); table.AddCell(new Phrase(&#34;Head&#34;, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12))); table.AddCell(new Phrase(&#34;Amount &#34;, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12))); int k = 1; for (int j = 2; j &lt; sTable.Columns.Count; j++) { dt1.Rows.Add(sTable.Rows[i][j]); table.AddCell(new Phrase(&#34;&#34; + k, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12))); table.AddCell(new Phrase(&#34;&#34; + sTable.Columns[j].ColumnName, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12))); table.AddCell(new Phrase(&#34;&#34; + sTable.Rows[i][j], FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12))); k++; } int sum = Convert.ToInt32(dt1.Compute(&#34;sum(Amount)&#34;, &#34;&#34;)); PdfPCell cellP = new PdfPCell(new Phrase(&#34;Payable Amount: &#34; + sum, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12))); cellP.Colspan = 4; cellP.Padding = 8f; cellP.HorizontalAlignment = 1; table.AddCell(cellP); doc.Add(table); doc.NewPage(); } doc.Close(); MessageBox.Show(&#34;Fees Generated Successfully&#34;, &#34;Information&#34;, MessageBoxButtons.OK, MessageBoxIcon.Information); return; }</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/wNSro7z.gif" alt="" /></p>https://www.aspforums.net:443/Threads/468424/Display-Column-Sum-while-generating-PDF-using-C-in-Windows-Application/https://www.aspforums.net:443/Threads/468424/Display-Column-Sum-while-generating-PDF-using-C-in-Windows-Application/Fri, 10 May 2019 05:10:19 GMT