Free knowledge blog: linux, programming, open source, databases, android, frameworks, web and computing in general
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.
You have to download the plugin, it’s for free, just go to the next link:
If it asks you for firewall permission allow it, it is not a malicious file.
When you include the library, the classes
ConectorPluginV3 will be available.
Now you can create a new
let conector = new ConectorPluginV3(null, "optional license");
The class constructor accepts a distinct URL if you want to provide a different port in the future, you are not forced to indicate the URL, by defualt it is localhost:8000.
Once you have the instance, you can, for example, call the
EscribirTexto method (to write text) and finally the
imprimirEn method passing the printer’s name.
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.
If it returns
true, then it was successfull, if it does not, then the error message will be in the result variable.
Remember: you can check all the examples source code.
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
ConectorPluginV3 instance we can call
EscribirTexto to write simple text,
Feed to feed paper,
Pulso to open cash drawer,
ImprimirCodigoDeBarras to print barcode,
Corte to cut paper,
EstablecerAlineacion to align and finally
imprimirEn to print it in the printer we pass as argument.
Now you can use your thermal printer and create awesome receipts. The full docs are here: https://gist.github.com/parzibyte/2f36655ef9d6ea8e6de73c6e09bbc735#file-documentacion-txt