In this post I will show you how to print a receipt in a thermal printer directly from web browser, without user interaction and confirm dialogs, by using a free plugin.
Step 1: download the plugin
You have to download the plugin, it’s for free, just go to the docs. If it asks you for firewall permission allow it, it is not a malicious file.
When you include the library, the classes
Impresora will be available.
Step 3: set up default printer
Here you can use the
setImpresora method (call it with a printer obtained from
getImpresoras), or go to the examples and use the buttons.
Step 4: hello, thermal printer
Now you can create a new
let impresora = new Impresora();
The class constructor accepts a distinct URL if you want to provide an IP or if I change the port in the future, you are not forced to indicate the URL, by defualt it is localhost:8080
Once you have the instance, you can, for example, call the
write method and finally the
When the promise is resolved you should get a ticket printed in your thermal printer, if not, check the docs again and make sure you followed all the steps.
Remember: you can check all the examples source code.
Example: plugin capabilities
We will get a ticket like this, where we can set the font, alignment and some other things:
The code is as follows:
Once we have an
Impresora instance we can call
setFontSize and finally
Now you can use your thermal printer and create awesome receipts.