Background
In a project which needs to print receipt using heat sensitive printer, I successfully print out the receipt for each take away ordering, like below
Existing version of the receipt contains only text, using node module printer I was able to print the text properly, but recently a new request requires to print the qr code, which is in the form of an image, which this node module is not supported.
Somehow only CUPS printer support image printing which is not what Windows is supporting...
Solutions
So luckily I keep searching in the issue thread of the node printer plugin, and found this thread.
So from the reply, I agree that there is no need for me to use time for finding node plugins, instead I follow the path to use a Windows application "printhtml" to first generate a HTML file and then print it.
Although it is quite a bit complicated, as I need to create a child process in my node application and execute the remote command, but it finally works.
Steps
- In loopback application, send socket message to the remote node daemon which that PC is connecting to the printer.
- The node daemon received the socket message and generate the HTML file (with the QR code image)
- Execute the child process and run the printhtml executable and print success.
- https://www.npmjs.com/package/qrcode#qr-code-options
- https://www.npmjs.com/package/printer
- https://stackoverflow.com/questions/17242516/mingw-w64-threads-posix-vs-win32
- https://github.com/tojocky/node-printer/issues/206
- https://github.com/tojocky/node-printer/issues/20
- https://stackoverflow.com/questions/23437804/is-it-possible-to-print-an-image-with-node-js
- http://www.printhtml.com/
- https://stackoverflow.com/questions/21617468/node-js-generate-html
沒有留言:
張貼留言