<script type="text/javascript"> function PrintPanel() { var panel = document.getElementById("<%=pnlContents.ClientID %>"); var printWindow = window.open('', '', 'height=500,width=800'); printWindow.document.write('<html><head><title>DIV Contents</title>'); printWindow.document.write('</head><body >'); printWindow.document.write(panel.innerHTML); printWindow.document.write('</body></html> <div class="container" style="text-align: center"> <h2>QR Code Print</h2> <div class="row"> <div class="col-4"></div> <div class="col-4"> <div class="form-group"> <asp:Panel ID="pnlContents" runat="server"> <asp:Label ID="lblJobcode" runat="server" /> <asp:PlaceHolder ID="plBarCode" runat="server" /> </asp:Panel> <div class="input-group"> <div class="input-group-append"> <asp:Button ID="BtnGenerateQRCode" runat="server" Text="Print QR Code" CssClass="btn btn-primary" OnClientClick="return PrintPanel();"/> </div> </div> </div> </div> <div class="col-4"></div> </div> </div>
CS
if (Request.QueryString["GenSampleCode"] != null) { int GenSampleCode = Convert.ToInt32(Request.QueryString["GenSampleCode"]); DataTable aDtGenSampleCode = new DataTable(); DataTable PivotDatatable = new DataTable(); aDtGenSampleCode = QualityReport.SP_TruckWiseSampleDtlsQrPrint_V2(GenSampleCode); aDtGenSampleCode.Columns.Cast<DataColumn>() .ToList() .ForEach(c => c.ColumnName = aDtGenSampleCode.Rows[0][c.Ordinal].ToString()); aDtGenSampleCode.Rows.RemoveAt(0); PivotDatatable = GenerateTransposedTable(aDtGenSampleCode);//PivoteDataTable.Pivot(aDtGenSampleCode); foreach (DataRow dtRow in PivotDatatable.Rows) { foreach (var item in dtRow.ItemArray) { System.Web.UI.WebControls.Image imgbarcode = new System.Web.UI.WebControls.Image(); System.Web.UI.WebControls.Label lblcode = new System.Web.UI.WebControls.Label(); string code = item.ToString(); imgbarcode.Height = 175; imgbarcode.Width = 175; var writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; var result = writer.Write(code); string path = Server.MapPath("~/Images/QRImages.jpg"); var barcodeBitmap = new Bitmap(result); using (MemoryStream memory = new MemoryStream()) { using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite)) { barcodeBitmap.Save(memory, ImageFormat.Jpeg); byte[] bytes = memory.ToArray(); imgbarcode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes); } lblJobcode.Text = code; plBarCode.Controls.Add(imgbarcode); } } } } private DataTable GenerateTransposedTable(DataTable inputTable) { DataTable outputTable = new DataTable(); // Add columns by looping rows // Header row's first column is same as in inputTable outputTable.Columns.Add(inputTable.Columns[0].ColumnName.ToString()); // Header row's second column onwards, 'inputTable's first column taken foreach (DataRow inRow in inputTable.Rows) { string newColName = inRow[0].ToString(); outputTable.Columns.Add(newColName); } // Add rows by looping columns for (int rCount = 1; rCount <= inputTable.Columns.Count - 1; rCount++) { DataRow newRow = outputTable.NewRow(); // First column is inputTable's Header row's second column newRow[0] = inputTable.Columns[rCount].ColumnName.ToString(); for (int cCount = 0; cCount <= inputTable.Rows.Count - 1; cCount++) { string colValue = inputTable.Rows[cCount][rCount].ToString(); newRow[cCount + 1] = colValue; } outputTable.Rows.Add(newRow); } return outputTable; }