Day three of printer research, deep water.
Problems solved and knowledge mastered:
The format of printing commands and BIN/HEX
But there are still problems:
A simple command can be such as the initial print is ESC @, which is easier to write. What if it’s a complicated picture? What about pictures? The original question is very difficult to understand. As shown in figure. Qr code is the same, it looks very complicated.
www.epson-biz.com/modules/ref…
The problem with images is that you need to replace the original image with a bitmap, a bitmap. This is algorithmically supported.
The problem with two-dimensional code is: format adjustment is more troublesome, and some printers do not support!!
Solution: QR Code is also an image printing solution, that is, generate an image and print it.
So the question becomes: How do you print pictures?
If you follow the native format to adjust, very troublesome. Is there a way to convert programs to binary by simply writing commands? Yes, as shown!
This coding program also has image support, so it works! This code returns Unit8Array, similar to [34,45,68], which needs to be converted to hex in the following format:
There are three issues that need to be addressed:
- Unit8Array becomes \ XLB \x40
- Since the symbol escape \ is needed for the conversion, a regular expression conversion is required to convert two \ into one \, as shown in the figure below.
hex2cmds(hexStr){
return hexStr.replace(/\\x([0-9A-F]{2})/gi, function() {
// console.log(arguments);
return String.fromCharCode(parseInt(arguments[1], 16));
});
},
buffer2hex(buffer) { // buffer is an ArrayBuffer
return Array.prototype.map.call(new Uint8Array(buffer), x => ("\\x"+ ('00' + x.toString(16)).slice(-2)) ).join(' ');
},
Copy the code
Picture problem solved, two-dimensional code problem is easy to say!! Print the qr code directly. Now the question is: how to determine the size of the two-dimensional code print picture? So if I set the image to 100 px, how big will it print? Here comes the size of the Pixel in the physical world.
The DPI varies from printer to printer. For 203 dot per inch, each dot is 0.125mm, so for 100px, the DPI is 12.5mm. And tested, if the TWO-DIMENSIONAL code is too small, scan code can not come out. Make it bigger, like 100px.
How to solve Chinese characters? This is related to printer Settings, you need to write codePage code to the printer, otherwise Chinese cannot be printed, so you need to use the following command, ok? It’s easier than writing native:
How to print on the server? Because printing happens mostly on the client side, printing on the server side is not very useful and somewhat problematic. For example, pictures need to be rendered with canvas, and there are some problems with Chinese coding. Therefore, it is better to print mainly on the browser side.