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.Print QRCode image using C# and VB.Net in ASP.Net<p>Hi&nbsp;narasiman,</p> <p>Put the&nbsp;PlaceHolder inside a Panel or DIV and the refer the following article for print.</p> <p><a href="http://www.aspsnippets.com/Articles/Print-ASPNet-Panel-contents-in-ASPNet-using-C-VBNet-and-JavaScript.aspx">Print ASP.Net Panel contents in ASP.Net using C# VB.Net and JavaScript</a></p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:TextBox ID=&#34;txtCode&#34; runat=&#34;server&#34;&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID=&#34;btnGenerate&#34; runat=&#34;server&#34; Text=&#34;Generate QR Code&#34; OnClick=&#34;GenerateQRCode&#34; /&gt; &lt;asp:Button ID=&#34;btnPrint&#34; runat=&#34;server&#34; Text=&#34;Print&#34; OnClientClick=&#34;return PrintPanel();&#34; /&gt; &lt;hr /&gt; &lt;asp:Panel ID=&#34;pnlContents&#34; runat=&#34;server&#34;&gt; &lt;asp:PlaceHolder ID=&#34;plBarCode&#34; runat=&#34;server&#34; /&gt; &lt;/asp:Panel&gt; &lt;script type=&#34;text/javascript&#34;&gt; function PrintPanel() { var panel = document.getElementById(&#34;&lt;%=pnlContents.ClientID %&gt;&#34;); var printWindow = window.open(&#39;&#39;, &#39;&#39;, &#39;height=400,width=800&#39;); printWindow.document.write(&#39;&lt;html&gt;&lt;head&gt;&lt;title&gt;DIV Contents&lt;/title&gt;&#39;); printWindow.document.write(&#39;&lt;/head&gt;&lt;body &gt;&#39;); printWindow.document.write(panel.innerHTML); printWindow.document.write(&#39;&lt;/body&gt;&lt;/html&gt;&#39;); printWindow.document.close(); setTimeout(function () { printWindow.print(); }, 500); return false; } &lt;/script&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Drawing; using System.IO; using QRCoder;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Drawing Imports System.IO Imports QRCoder</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void GenerateQRCode(object sender, EventArgs e) { string code = txtCode.Text; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); imgBarCode.Height = 150; imgBarCode.Width = 150; using (Bitmap bitMap = qrCode.GetGraphic(20)) { using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); imgBarCode.ImageUrl = &#34;data:image/png;base64,&#34; + Convert.ToBase64String(byteImage); } plBarCode.Controls.Add(imgBarCode); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub GenerateQRCode(ByVal sender As Object, ByVal e As EventArgs) Dim code As String = txtCode.Text Dim qrGenerator As QRCodeGenerator = New QRCodeGenerator() Dim qrCode As QRCodeGenerator.QRCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q) Dim imgBarCode As System.Web.UI.WebControls.Image = New System.Web.UI.WebControls.Image() imgBarCode.Height = 150 imgBarCode.Width = 150 Using bitMap As Bitmap = qrCode.GetGraphic(20) Using ms As MemoryStream = New MemoryStream() bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png) Dim byteImage As Byte() = ms.ToArray() imgBarCode.ImageUrl = &#34;data:image/png;base64,&#34; &amp; Convert.ToBase64String(byteImage) End Using plBarCode.Controls.Add(imgBarCode) End Using End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/TfNvYyW.gif" alt="" width="472" height="372" /></span></strong></p>https://www.aspforums.net:443/Threads/175536/Print-QRCode-image-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/175536/Print-QRCode-image-using-C-and-VBNet-in-ASPNet/Thu, 13 Dec 2018 04:27:54 GMT