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.Generate Invoice (Bill) Receipt with Image PDF from database in ASP.Net using C# and VB.Net<p>Hi <a class="username" rel="Sadakat"> Sadakat</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html"> &lt;asp:Button ID=&#34;Button1&#34; Text=&#34;Generate Invoice&#34; OnClick=&#34;GenerateInvoicePDF&#34; runat=&#34;server&#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.Text; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.html.simpleparser;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.IO Imports iTextSharp.text.html.simpleparser Imports iTextSharp.text.pdf Imports iTextSharp.text</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>&nbsp;C#</strong></p> <pre class="brush: csharp">protected void GenerateInvoicePDF(object sender, EventArgs e) { string path = Server.MapPath(&#34;~/File/2.png&#34;); StringBuilder sb = new StringBuilder(); sb.Append(&#34;&lt;div align=&#39;center&#39;;&gt;&#34;); sb.Append(@&#34;&lt;img src=&#39;&#34; + path + &#34;&#39; height=&#39;50px&#39; width=&#39;50px&#39; /&gt;&#34;); sb.Append(&#34;&lt;h2&gt;AL-MADANI INTERNATIONAL&lt;/h2&gt;&lt;table class=&#39;table table-bordered&#39;&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;Invoice No.&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Invoice Date:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;Tourist Name:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Total Passengers:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;City:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;District:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;State:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Post Code:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;Payment Mode:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Payment Date:&lt;/td&gt;&lt;tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;Payment Details*:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Journey Date:&lt;/td&gt;&lt;tr&gt;&lt;th colspan=&#39;6&#39;&gt;DETAILS OF RECEIVER - BILLED TO&lt;/th&gt;&lt;tr&gt;&lt;td colspan=&#39;6&#39;&gt;Name:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;6&#39;&gt;Address:&lt;/td&gt;&lt;/tr&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;3&#39;&gt;Description&lt;/th&gt;&lt;th&gt;Rate&lt;/th&gt;&lt;th&gt;Total Passenger&lt;/th&gt;&lt;th&gt;Total Amount&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;ECONOMY PACKAGE FOR UMRAH ON OCTOBER 2019&lt;/td&gt;&lt;td&gt;40000&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;80000&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;PAID AMOUNT = &lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;BALANCE AMOUNT = &lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;6&#39;&gt;TOTAL&lt;/tr&gt;&lt;tr&gt;&lt;/th&gt;&lt;th colspan=&#39;3&#39; rowspan=&#39;5&#39;&gt;Amount in words&lt;/th&gt;&lt;th colspan=&#39;2&#39;&gt;Total Amount&lt;/th&gt;&lt;td&gt;80000&lt;/td&gt;&lt;tr&gt;&lt;th colspan=&#39;2&#39;&gt;.&lt;/th&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;2&#39;&gt;.&lt;/th&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;2&#39;&gt;.&lt;/th&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;2&#39;&gt;Grand Total&lt;/th&gt;&lt;td&gt;80000&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#34;); sb.Append(&#34;&lt;/div&gt;&#34;); StringReader sr = new StringReader(sb.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.ContentType = &#34;application/pdf&#34;; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment;filename=Invoice_&#34; + &#34;invoice&#34; + &#34;.pdf&#34;); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfDoc); Response.End(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub GenerateInvoicePDF(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Dim path As String = Server.MapPath(&#34;~/File/2.png&#34;) Dim sb As StringBuilder = New StringBuilder() sb.Append(&#34;&lt;div align=&#39;center&#39;;&gt;&#34;) sb.Append(&#34;&lt;img src=&#39;&#34; &amp; path &amp; &#34;&#39; height=&#39;50px&#39; width=&#39;50px&#39; /&gt;&#34;) sb.Append(&#34;&lt;h2&gt;AL-MADANI INTERNATIONAL&lt;/h2&gt;&lt;table class=&#39;table table-bordered&#39;&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;Invoice No.&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Invoice Date:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;Tourist Name:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Total Passengers:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;City:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;District:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;State:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Post Code:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;Payment Mode:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Payment Date:&lt;/td&gt;&lt;tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;Payment Details*:&lt;/td&gt;&lt;td colspan=&#39;3&#39;&gt;Journey Date:&lt;/td&gt;&lt;tr&gt;&lt;th colspan=&#39;6&#39;&gt;DETAILS OF RECEIVER - BILLED TO&lt;/th&gt;&lt;tr&gt;&lt;td colspan=&#39;6&#39;&gt;Name:&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;6&#39;&gt;Address:&lt;/td&gt;&lt;/tr&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;3&#39;&gt;Description&lt;/th&gt;&lt;th&gt;Rate&lt;/th&gt;&lt;th&gt;Total Passenger&lt;/th&gt;&lt;th&gt;Total Amount&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;ECONOMY PACKAGE FOR UMRAH ON OCTOBER 2019&lt;/td&gt;&lt;td&gt;40000&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;80000&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;PAID AMOUNT = &lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;tr&gt;&lt;td colspan=&#39;3&#39;&gt;BALANCE AMOUNT = &lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;6&#39;&gt;TOTAL&lt;/tr&gt;&lt;tr&gt;&lt;/th&gt;&lt;th colspan=&#39;3&#39; rowspan=&#39;5&#39;&gt;Amount in words&lt;/th&gt;&lt;th colspan=&#39;2&#39;&gt;Total Amount&lt;/th&gt;&lt;td&gt;80000&lt;/td&gt;&lt;tr&gt;&lt;th colspan=&#39;2&#39;&gt;.&lt;/th&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;2&#39;&gt;.&lt;/th&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;2&#39;&gt;.&lt;/th&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th colspan=&#39;2&#39;&gt;Grand Total&lt;/th&gt;&lt;td&gt;80000&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#34;) sb.Append(&#34;&lt;/div&gt;&#34;) Dim sr As StringReader = New StringReader(sb.ToString()) Dim pdfDoc As Document = New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F) Dim htmlparser As HTMLWorker = New HTMLWorker(pdfDoc) Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream) pdfDoc.Open() htmlparser.Parse(sr) pdfDoc.Close() Response.ContentType = &#34;application/pdf&#34; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment;filename=Invoice_&#34; &amp; &#34;invoice&#34; &amp; &#34;.pdf&#34;) Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.Write(pdfDoc) Response.[End]() End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/rBie97v.jpg" alt="" width="472" height="257" /></p>https://www.aspforums.net:443/Threads/209678/Generate-Invoice-Bill-Receipt-with-Image-PDF-from-database-in-ASPNet-using-C-and-VBNet/https://www.aspforums.net:443/Threads/209678/Generate-Invoice-Bill-Receipt-with-Image-PDF-from-database-in-ASPNet-using-C-and-VBNet/Mon, 20 May 2019 01:56:27 GMT