In this tutorial we will see how to send instructions to a thermal printer using VB.NET on Visual Studio 2022.
Introduction
Often, to use a thermal printer it is necessary to use the ESC POS commands, but this is not always possible.
In one of the programs I created, I found myself having to print labels using a small thermal printer that would have been supplied with the operator station.
This printer (by HPRT) had its own driver which, once installed, allowed it to be used as a normal printer. So initially I proceeded to print the labels in bitmap format. Needless to say, the result was bad, but good enough for the barcodes to be read without problems.
With the main development done, it’s time to fix those little residual defects… including the print quality of the labels.
After a quick Google search here’s the solution: send the print information as raw, rather than as a bitmap. Sending the raw information shouldn’t have been too complex: the printer had a well done datasheet with all the ESC POS commands clearly shown.
What was the problem then? In order to communicate with the printer I should have used a COM port, pity that the printer was on the USB001 port. The standard solution would have been to re-install the drivers and configure a virtual COM port, pointing to USB001.
Now consider that I was developing a bespoke program for a small company in my city. Therefore a single program to be installed on different computers, possibly autonomously by clicking on a simple installer.
So I immediately discarded the COM port virtualization, and here’s how I solved the problem.
Goals
Make quality prints with a thermal printer without using a virtual port
Procedure
We will start from the following assumptions:
- You have already downloaded and installed Visual Studio 2022
- You have already downloaded and installed your printer drivers
- The printer appears in the list of installed printers
The first thing to do after creating the project is to download the Simple .NET POSPrinter library and add the POSPrinter.vb file to the solution.
Note:
On github you will also find a demo project that you can use as a reference for using the library and its functions
Before proceeding to use the library you will also need to include the necessary resources in the project:
- System.Drawing.Printing
- ZXing
- ZXing.Common

Using the library is very simple. Two buttons are sufficient, which we can group into one if desired: the printer selection button and the print button.
I’m going to skip over the first button (which does nothing but open the printer selection dialog and memorize the choice) and go straight to illustrating how to proceed with printing:

As you can see from the code in the screenshot above, pressing the button simply goes to:
- Create a new PrintDocument() called pd
- Add the selected printer to pd
- Add printTestLabel as handler of pd
It is then necessary to specify what must be printed, and this is done in the print manager printTestLabel, below is a part of the code:

As you can see, you start by specifying a font among those supported by the printer and a brush (always black unless the printer supports multiple colors).
We then use the functions of the Simple .NET POSPrinter library to print:
| .PrintText(String) | Print a String |
| .PrintTextLn(String) | Print a String and move cursor the the begin of next line |
| .PrintHLine() | Print an horizontal line |
| .EmptyLine() | Leave a white space |
| .PrintBarcode(String, BarcodeOptions, BarcodeFormat) | Print a barcode |
Conclusion
We managed to print a simple example through a thermal printer, without using either ESC POS commands or virtual ports.
At the beginning of the article you can find a photo of a label printed with this method. Here are the results of printing as a bitmap:

As you can see the quality of the writing is not the best, and the barcode is very bad.