Free knowledge blog: linux, programming, open source, databases, android, frameworks, web and computing in general
When printing receipts on thermal printers (ESC POS) sometimes it is needed to print images of any type, for example, to print the customer’s logo and so on.
In this post I will show you how to print any kind of images: you will be able to print local images, base64 images and internet images.
To send ESC POS commands to the POS printer we need something to start the communication. That’s why I have developed a free plugin that creates a server on the user’s PC.
I have explained it in the next post, I encourage you to read it, download the plugin and share your printer:
For the next section I assume that you have already printed the “hello world” receipt in your thermal printer.
Let’s start learning how to send a URL-based image to a thermal printer. This must be a public URL. It could be from a public internet site:
Or it can be from your domain, for example:
It can even be from localhost:
In the end, it should be a valid internet URL. To do this, we invoke the function
Just remember that the plugin will download the image and leave a trace of the connection, assuming that the URL destination is a valid image. Therefore, only use images from sites you trust.
A local image is the one that is located on the computer where the plugin is installed, and its location is something like
To print a local image, we invoke the function
Remember that you can invoke this method multiple times.
The thermal printer image printing plugin also allows printing images in base64 format, which means you can send the image as a string.
To print a base64 image from the plugin, whether with JS, Python, Java, or any other language, we call the
In this example, I am taking the values from text fields, but you can define them from anywhere.
Please note that when you call a function to print an image, the arguments are:
ConectorPluginV3.TAMAÑO_IMAGEN_NORMALand it’s not the image width, but an internal resize config in the thermal printer
Also, sometimes it is necessary to call
Feed(1) before printing an image, and also sometimes we need to call
Iniciar (to reset printer to power-on status) after we print an image.
As always, remember that you can try and make tests combining available functions.
The plugin supports only JPG and PNG images. Remember that you can change the width, but it must always be a multiple of 8.
Keep in mind that the printer will only print in black and white, and it will consider some colors as white if they are very light. That’s why if you want optimal results, you should create the image in black and white from the beginning.
However, the best way is to try with your own images and draw conclusions. Remember that you can find everything you need in this post.
By the way, you can also check out the Bluetooth thermal printer plugin for Android.