How to print small text on Zebra ZPL-EPL thermal printers by using ThermalLabel SDK for .NET

Prerequisites
  • Neodynamic ThermalLabel SDK 4.0 for .NET
  • Microsoft .NET Framework 3.5 (or greater)
  • Microsoft Visual Studio 2008 / 2010
  • Microsoft Visual Studio 2008 / 2010 Express Editions (VB, C#, J#, and C++)
  • Any Zebra Thermal Printer supporting ZPL (Zebra Programming Language) or EPL (Eltron Programming Language)


Printing small text on thermal labels is a common request in some industries like Healthcare, Manufacturing, Retail, Security, Transportation, etc.

By printing small text, we mean text which font size is about 0.04 inch (about 1 millimiter) high. Printing such font size is not a problem at all if your thermal printer provides 300 or 600 dpi output printing resolution because you can use almost any TrueType font with the TextItem object and get a crisp and clear text after printing the label.

The problem arises if you are targeting or using a thermal printer which is 203 dpi. That resolution is commonly found on "Desktop thermal printers" although it is also found on "Midrange" and "High Performance" printers too. If your printer is 203 dpi, then getting a crisp and clear small text involves carefully selecting the TrueType font.

In ThermalLabel SDK we provide a solution to that scenario by using the so called "Bitmap or Pixel fonts". On any TextItem object, you enable these kind of fonts by setting up the IsBitmapFont property to True and specifying the correct size of the font using the Size and Unit properties.

We have made a couple of tests with some Bitmap/Pixel fonts available on the web. The following is the list of tested fonts and the minimum size for getting the smallest readable texts, mainly on 203 dpi printers:


The following code generates six TextItem objects featuring each font metioned above. Notice that IsBitmapFont property is set to True and the Unit and Size of the font are set up to the minimum size. The sample project is a Windows Forms app, which displays a preview of the generated thermal label at 203 dpi. This allows you to test how the TrueType font file will look like before printing.

Please follow up these steps:
  • Download all the fonts stated above to the C:\temp\test_fonts\ folder. For simplicity, we have packaged them into this file BitmapFontsForSmallTextPrinting.zip
    IMPORTANT: Please review license terms for each font referring to their author sites.
  • Open Visual Studio 2008/2010 (or any Visual Studio Express 2008/2010 edition) and create a new Windows Forms project. Please ensure to select .NET 3.5 Framework or greater (Remember that ThermalLabel SDK does support .NET Client Profile too)
  • On the default Form1, please add a TextBox, a Button and a PictureBox. Select the PictureBox and set the SizeMode property to AutoSize
  • Add a reference to ThermalLabel SDK dll i.e. Neodynamic.SDK.ThermalLabel.dll
  • Double click on the Button and paste this code:

    Visual Basic .NET
    Dim dpi As Double = 203

    Dim sampleText As String = Me.textBox1.Text

    Dim tLabel As New ThermalLabel(UnitType.Inch, 3, 2)
    tLabel.GapLength = 0.1

    Dim txt1 As New TextItem(0.1, 0.1, 2.8, 0.25, "")
    txt1.Font.Name = "Arial"
    txt1.Font.Unit = FontUnit.Point
    txt1.Font.Size = 6
    txt1.Text = txt1.Font.Name + ": " + sampleText

    Dim txt2 As New TextItem(0.1, 0.35, 2.8, 0.25, "")
    txt2.Font.CustomFontFile = "C:\temp\test_fonts\crisp.ttf"
    txt2.Font.CustomFontFileFamilyName = "Crisp"
    txt2.Font.IsBitmapFont = True
    txt2.Font.Unit = FontUnit.Point
    txt2.Font.Size = 6
    txt2.Text = txt2.Font.CustomFontFileFamilyName + ": " + sampleText

    Dim txt3 As New TextItem(0.1, 0.6, 2.8, 0.25, "")
    txt3.Font.CustomFontFile = "C:\temp\test_fonts\MonteCarloFixed12.ttf"
    txt3.Font.CustomFontFileFamilyName = "MonteCarlo Fixed 12"
    txt3.Font.IsBitmapFont = True
    txt3.Font.Unit = FontUnit.Point
    txt3.Font.Size = 6
    txt3.Text = txt3.Font.CustomFontFileFamilyName + ": " + sampleText

    Dim txt3b As New TextItem(0.1, 0.85, 2.8, 0.25, "")
    txt3b.Font.CustomFontFile = "C:\temp\test_fonts\MonteCarloFixed12-Bold.ttf"
    txt3b.Font.CustomFontFileFamilyName = "MonteCarlo Fixed 12"
    txt3b.Font.IsBitmapFont = True
    txt3b.Font.Unit = FontUnit.Point
    txt3b.Font.Size = 6
    txt3b.Text = txt3b.Font.CustomFontFileFamilyName + ": " + sampleText

    Dim txt4 As New TextItem(0.1, 1.1, 2.8, 0.25, "")
    txt4.Font.CustomFontFile = "C:\temp\test_fonts\TEACPSS_.ttf"
    txt4.Font.CustomFontFileFamilyName = "Teachers Pet Sans Serif"
    txt4.Font.IsBitmapFont = True
    txt4.Font.Unit = FontUnit.Point
    txt4.Font.Size = 3
    txt4.Text = txt4.Font.CustomFontFileFamilyName + ": " + sampleText

    Dim txt4b As New TextItem(0.1, 1.35, 2.8, 0.25, "")
    txt4b.Font.CustomFontFile = "C:\temp\test_fonts\TEACPSSB.ttf"
    txt4b.Font.CustomFontFileFamilyName = "Teachers Pet Sans Serif Bold"
    txt4b.Font.IsBitmapFont = True
    txt4b.Font.Unit = FontUnit.Point
    txt4b.Font.Size = 3
    txt4b.Text = txt4b.Font.CustomFontFileFamilyName + ": " + sampleText

    Dim txt5 As New TextItem(0.1, 1.6, 2.8, 0.25, "")
    txt5.Font.CustomFontFile = "C:\temp\test_fonts\kharon.ttf"
    txt5.Font.CustomFontFileFamilyName = "Kharon4a_v01"
    txt5.Font.IsBitmapFont = True
    txt5.Font.Unit = FontUnit.Point
    txt5.Font.Size = 3
    txt5.Text = txt5.Font.CustomFontFileFamilyName + ": " + sampleText

    tLabel.Items.Add(txt1)
    tLabel.Items.Add(txt2)
    tLabel.Items.Add(txt3)
    tLabel.Items.Add(txt3b)
    tLabel.Items.Add(txt4)
    tLabel.Items.Add(txt4b)
    tLabel.Items.Add(txt5)

    Using pj As New PrintJob()
    Using ms As New System.IO.MemoryStream()
    pj.ExportToImage(tLabel, ms, new ImageSettings(ImageFormat.Tiff), dpi)
    Me.pictureBox1.Image = Image.FromStream(ms)
    End Using
    End Using


    Visual C# .NET
    double dpi = 203;

    string sampleText = this.textBox1.Text;

    ThermalLabel tLabel = new ThermalLabel(UnitType.Inch, 3, 2);
    tLabel.GapLength = 0.1;

    TextItem txt1 = new TextItem(0.1, 0.1, 2.8, 0.25, "");
    txt1.Font.Name = "Arial";
    txt1.Font.Unit = FontUnit.Point;
    txt1.Font.Size = 6;
    txt1.Text = txt1.Font.Name + ": " + sampleText;

    TextItem txt2 = new TextItem(0.1, 0.35, 2.8, 0.25, "");
    txt2.Font.CustomFontFile = @"C:\temp\test_fonts\crisp.ttf";
    txt2.Font.CustomFontFileFamilyName = "Crisp";
    txt2.Font.IsBitmapFont = true;
    txt2.Font.Unit = FontUnit.Point;
    txt2.Font.Size = 6;
    txt2.Text = txt2.Font.CustomFontFileFamilyName + ": " + sampleText;

    TextItem txt3 = new TextItem(0.1, 0.6, 2.8, 0.25, "");
    txt3.Font.CustomFontFile = @"C:\temp\test_fonts\MonteCarloFixed12.ttf";
    txt3.Font.CustomFontFileFamilyName = "MonteCarlo Fixed 12";
    txt3.Font.IsBitmapFont = true;
    txt3.Font.Unit = FontUnit.Point;
    txt3.Font.Size = 6;
    txt3.Text = txt3.Font.CustomFontFileFamilyName + ": " + sampleText;

    TextItem txt3b = new TextItem(0.1, 0.85, 2.8, 0.25, "");
    txt3b.Font.CustomFontFile = @"C:\temp\test_fonts\MonteCarloFixed12-Bold.ttf";
    txt3b.Font.CustomFontFileFamilyName = "MonteCarlo Fixed 12";
    txt3b.Font.IsBitmapFont = true;
    txt3b.Font.Unit = FontUnit.Point;
    txt3b.Font.Size = 6;
    txt3b.Text = txt3b.Font.CustomFontFileFamilyName + ": " + sampleText;

    TextItem txt4 = new TextItem(0.1, 1.1, 2.8, 0.25, "");
    txt4.Font.CustomFontFile = @"C:\temp\test_fonts\TEACPSS_.ttf";
    txt4.Font.CustomFontFileFamilyName = "Teachers Pet Sans Serif";
    txt4.Font.IsBitmapFont = true;
    txt4.Font.Unit = FontUnit.Point;
    txt4.Font.Size = 3;
    txt4.Text = txt4.Font.CustomFontFileFamilyName + ": " + sampleText;

    TextItem txt4b = new TextItem(0.1, 1.35, 2.8, 0.25, "");
    txt4b.Font.CustomFontFile = @"C:\temp\test_fonts\TEACPSSB.ttf";
    txt4b.Font.CustomFontFileFamilyName = "Teachers Pet Sans Serif Bold";
    txt4b.Font.IsBitmapFont = true;
    txt4b.Font.Unit = FontUnit.Point;
    txt4b.Font.Size = 3;
    txt4b.Text = txt4b.Font.CustomFontFileFamilyName + ": " + sampleText;

    TextItem txt5 = new TextItem(0.1, 1.6, 2.8, 0.25, "");
    txt5.Font.CustomFontFile = @"C:\temp\test_fonts\kharon.ttf";
    txt5.Font.CustomFontFileFamilyName = "Kharon4a_v01";
    txt5.Font.IsBitmapFont = true;
    txt5.Font.Unit = FontUnit.Point;
    txt5.Font.Size = 3;
    txt5.Text = txt5.Font.CustomFontFileFamilyName + ": " + sampleText;

    tLabel.Items.Add(txt1);
    tLabel.Items.Add(txt2);
    tLabel.Items.Add(txt3);
    tLabel.Items.Add(txt3b);
    tLabel.Items.Add(txt4);
    tLabel.Items.Add(txt4b);
    tLabel.Items.Add(txt5);

    using (PrintJob pj = new PrintJob())
    {
    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
    {
    pj.ExportToImage(tLabel, ms, new ImageSettings(ImageFormat.Tiff), dpi);

    this.pictureBox1.Image = Image.FromStream(ms);
    }
    }

  • Run the app and enter some text on the TextBox. Click on the button and you will get preview of all font settings.

    View figure...


Based on the output image preview of the label, you get that at 203 dpi, each font/size settings give the following text height:
  • Crisp.ttf (6pt), TEACPSS_.ttf (3pt) and TEACPSSB.ttf (3pt) at 203 dpi generate texts which whole height is about 0.044 inch (1.12 mm)
  • Both MonteCarloFixed12.ttf (6pt) and MonteCarloFixed12-Bold.ttf (6pt) at 203 dpi generate texts which whole height is about 0.034 inch (0.86 mm)
  • kharon.ttf (3pt) at 203 dpi generates a text which whole height is about 0.054 inch (1.37 mm)


Conclusions
  • If you need to print very small texts (about 0.04 inch or 1 mm high) on labels and your printer is 300 or 600 dpi, then almost any TrueType font at the right size do the job. But if your printer is 203 dpi, then use bitmap/pixel fonts instead.
  • Not all bitmap/pixel fonts are good for small text printing. Test them by using the code provided in this guide.
  • After the preview image output of a label featuring a given font is fine, please test it with your printer. In some cases, you will need to adjust the darkness settings on your printer for better text readability.



Links:
This Demos
Demos
Download ThermalLabel SDK for .NET
More Information about Neodynamic ThermalLabel SDK for .NET


Neodynamic
.NET Components & Controls
http://www.neodynamic.com
http://www.thermal-label.net