How to print barcode labels to the default thermal printer of the client machine in ASP.NET with ThermalLabel SDK

In this short article we’ll show you how to print to the default thermal printer of the client machine (a.k.a. client-side printing) without showing any print dialog to the end-user in an ASP.NET scenario by referring to the same scenario stated in our guide about ASP.NET Client-side cross-browser barcode thermal label printing with ThermalLabel SDK

Please read the above guide to learn more about how our client-side barcode thermal printing approach works before trying the following code.

To print to the default printer of the user (at the client machine) and based our code on the same wrote in our ASP.NET Client-side cross-browser barcode thermal label printing with ThermalLabel SDK guide, you should:

  • The first thing to do is to instruct to the user to set up in Windows OS the thermal printer as the default printer in the client machine. The following screenshot is from Windows 7 on which the user has set up the Zebra GK420tprinter as the default printer.
    Setting the default printer on Windows 7

    Note on the Windows Driver for the client printer.

    In this case the user installed the Zebra ZDesigner driver for the printer. However, in most cases the simple “Generic / Text Only” driver that comes with Windows will work just fine too.

  • The ThermalLabel SDK does support both Zebra ZPL and EPL printer languages i.e. on a given ThermalLabel object, you can instruct our product to generate ZPL or EPL commands and send them to the target printer. So the second important thing you need to knowis what kind of language the default client printer does support i.e. if it a ZPL or EPL printer. Some Zebra printer models (like the GK420t) do support both languages in which case you should not be worried about it (by default our SDK generates ZPL commands). However, others like the LP/TLP-2844 or TLP-3842 which only supports EPL should be taken into account.So you should get that info somehow from the client/user if this is a variable factor. In some enterprise scenarios, thing is sometimes simplified as the whole environment could be using the same printer model and then, the printer command language is already known. So please consider this topic when you need to “print to the default client printer”.
  • In addition to know the client printer’s language (ZPL or EPL) you also need to know the printing resolution (DPI) supported by the client printer. Nowadays, Zebra thermal printers come with 203, 300 and 600 dpi. The same method for getting if the client printer is ZPL or EPL capable may be applied for getting the DPI support.
  • So based on the above considerations, we could change the code from our main guide to the following. We know (somehow) that the printer is ZPL-capable and that it has 203 dpi of printing resolution. With that info we can print the label to the default client printer without showing any dialog to the user by modifying the code in the Page_Init event handler of our ASP.NET page to the following:

    For VB code:

    Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
    
            'is this a request for a WebPrintJob handler?
            If Not Request("webPrintJob") Is Nothing Then
                'Create a WebPrintJob obj
                Dim webPj As New WebPrintJob()
    
                'set a ThermalLabel obj
                webPj.ThermalLabel = GenerateBasicThermalLabel()
    
                'Print to the defaul client printer
                  webPj.ShowPrintDialog = False
                  webPj.PrinterSettings = New PrinterSettings()
                  webPj.PrinterSettings.Communication.CommunicationType = CommunicationType.PrinterDriver
                  webPj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
                  webPj.PrinterSettings.Dpi = 203
                  webPj.PrinterSettings.UseDefaultPrinter = True
    
                'Serialize WebPrintJob and send it back to the client
                'so it can be processed by the TLClientPrint utility
                Response.ContentType = "text/plain"
                Response.Write(webPj.ToString())
                Response.Flush()
                Response.End()
            End If
    
    End Sub
    
    

    For C# code:

    protected void Page_Init(object sender, EventArgs e)
    {
        //is this a request for a WebPrintJob handler?
        if (Request["webPrintJob"] != null)
        {
            //Create a WebPrintJob obj
            WebPrintJob webPj = new WebPrintJob();
    
            //set a ThermalLabel obj
            webPj.ThermalLabel = GenerateBasicThermalLabel();
    
            //Print to the defaul client printer
            webPj.ShowPrintDialog = false;
            webPj.PrinterSettings = new PrinterSettings();
            webPj.PrinterSettings.Communication.CommunicationType = CommunicationType.PrinterDriver;
            webPj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
            webPj.PrinterSettings.Dpi = 203;
            webPj.PrinterSettings.UseDefaultPrinter = true;
    
            //Serialize WebPrintJob and send it back to the client
            //so it can be processed by the TLClientPrint utility
            Response.ContentType = "text/plain";
            Response.Write(webPj.ToString());
            Response.Flush();
            Response.End();
        }
    }
    
    

    With that change of the Page_Init event handler, when the user clicks on the “Print Basic Label…” button of the page, the TLClientPrint utility will run and based on the WebPrintJob settings we did, the label should automatically be printed to the client printer without showing any print dialog at all.

If you need further assistance do not hesitate to contact our tech support.

ThermalLabel SDK 5.0 Updated – Fixed a bug in WebPrintJob, TLClientPrint utility, and Postnet-Planet barcode if using the Native Barcode Engine

The second maintenance release of ThermalLabel SDK 5.0 is now available containing the following:

  • Fixed! A bug when using data binding labels with the new WebPrintJob class.
  • Improved! The TLClientPrint utility was updated to read the internal stream fully and avoid some potential issues within some scenarios.
  • Fixed! The USPS Postnet and Planet symbologies were not correctly printed when using the Native Barcode Engine.

You can download and update the product by using the download link which can be found in the license email or in the Download section of our website.

The “Assembly Version” of the dlls have not changed but the “File Version”. Here is the list of all new “File version” attributes:

  • Neodynamic.SDK.ThermalLabel.dll patched to v5.0.3500.2
  • TLClientPrint.exe patched to v1.0.3500.1

Barcode Professional for Reporting Services and the System.BadImageFormatException

You deploy the Neodynamic.ReportingServices.Barcode.dll to the Report Server’s Bin folder and at report rendering stage (or at runtime) you get the following error message or something similar to this:

Exception caught instantiating NeodynamicBarcodeControl report server extension: System.BadImageFormatException: Could not load file or assembly ‘Neodynamic.ReportingServices.Barcode’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

This is likely to happen if your SQL Server Reporting Services is a 64bit edition and you deployed the Neodynamic.ReportingServices.Barcode.dll which was built/compiled for x86 platform (32bit) instead of deploying the barcode dll which was built for x64. So, to solve the issue, you need to copy (deploy) the Neodynamic.ReportingServices.Barcode.dll for x64 which you can find in the installation folder of our product. If this does not solve the issue, then contact our support team.

ThermalLabel SDK 5.0 Updated – New WebPrintJob and TLClientPrint utility, fixed an odd behavior of TextItem in the Visual Editor and a change for data bound items

The first maintenance release of ThermalLabel SDK 5.0 is now available containing the following:

  • New! The new WebPrintJob class plus the new TLClientPrint utility allows you to print thermal label objects served from an ASP.NET website to the client printer! Take a look at the ASP.NET Client-side cross-browser barcode thermal label printing with ThermalLabel SDK for getting started with these new features! (more guides on this topic will be available soon)

    ASP.NET Client-side cross-browser barcode thermal label printing with ThermalLabel SDK

    ASP.NET Client-side cross-browser barcode thermal label printing with ThermalLabel SDK

  • Changed! In the Visual Label Editor, when a TextItem or BarcodeItem is data bound (through the DataField property), now an icon/image will appear on the upper-left corner of the item and a tool tip with the DataField content will appear if mouse pointer is over it. TextItem now are editable even if a DataField is specified.
  • Fixed! In the Visual Label Editor, an odd behavior of the caret in the text edit box when using the Native Printer Fonts was fixed.

You can download and update the product by using the download link which can be found in the license email or in the Download section of our website.
The “Assembly Version” of the dlls have not changed but the “File Version”. Here is the list of all new “File version” attributes:

  • Neodynamic.SDK.ThermalLabel.dll patched to v5.0.3500.1
  • Neodynamic.Windows.ThermalLabelEditor.dll patched to v5.0.3500.1