This plugin allows you to print directly from browsers, without dialogs and without browsers compatibility issues because you only have to send a HTTP request to print silently and in the background.
That’s why I created the solution to the problem and I come to expose it. And no, it is not a misleading post.
A free plugin for printing in thermal printers directly from browser
If you want to jump to the examples or download the plugin, go to the docs.
What comes next are technical details of how the plugin works.
Sordid details following…
How does it work?
The operation is simple. The plugin, which is an executable, creates a web server on port 8080 (which only lives while the plugin is running) and listens for requests.
The plugin behaviour is best illustrated with the above image.
Because the plugin speaks HTTP, a ticket can be printed from any programming language that can communicate with the plugin.
Not all tickets are the same, and that is why I had to create a way to make the user print and modify editable and custom tickets.
To do this, I made an array where the actions are placed. Within the plugin I simply interpret them and send them to the printer.
Actions are an object that has “accion” (like write) and “datos”, which is the data used for the action.
It looks best illustrated in this class:
Both things, “accion” and “datos”, are converted to string.
All these actions are added to an array; through the methods that the
Impresora class exposes:
This class simply tries to validate the data a bit, but in the end, what is sent in the
end method is an array of objects.
On the server side that is also validated, and that’s all.
Minify the library, detect bugs, and so on.
Remember that this is a technical explanation, you can see the examples in the official docs.