Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to print the barcode from barcode printer, the size of barcode label is 2.5cm in height & width is 5cm that is from client side.
Here my problem is, when ever I try to customize the size of the barcode, the window size is customizing not the barcode size that is present in document in windows.print().
I have tried a lot but I couldn't, here in below coding I tried to adjust the document size in window but window is not appearing when I click Print button.

Pls help to bring the exact document size in window & make it to print the barcode...

C#
<asp:Button ID="btnPrint"  runat="server" ToolTip="Click Here to Print"
               OnClientClick="ClientSidePrint('divprint');"
               CssClass="add_btn" Text="Print" Height="25" />

               function ClientSidePrint(divBarcodeLabel) {
               var s = $find('MPE1');
               s.show();
               document.getElementById("subhead").style.display = "block";
               var w = 378;
               var h = 283;
               var l = (window.screen.availWidth - w) / 2;
               var t = (window.screen.availHeight - h) / 2;

               var sOption = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=" + w + ",height=" + h + ",left=" + l + ",top=" + t;
               // Get the HTML content of the div
               var sDivText = window.document.getElementById(divBarcodeLabel).innerHTML;
               // Open a new window
               var objWindow = window.open("", "Print", sOption);
               // Write the div element to the window
               objWindow.document.write(sDivText);
               objWindow.document.close();
               // Print the window
               objWindow.print();
               // Close the window
               objWindow.close();
           }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900