Bluetooth thermal printer - PT-210 - Lines are not displayed correctly
tc-maxx opened this issue · comments
Hello receiptline,
I have been printing to my Bluetooth thermal printer PT-210 from my website for a long time. So far I had not done any formatting and just printed text.
Now I came across this project and I think it's great. I would like to customize my receipts and also use QR codes and a logo.
With browserify I created and integrated the receiptline-full.js.
For my first test i want to print the following:
^^^^RECEIPT
12/18/2021, 11:22:33 AM
-
|Asparagus | 1| 1.00|
|Carrot | 3| 3.00|
-
^TOTAL | ^6.00
{code:https://receiptline.github.io/designer/; option:qrcode,3,L}
When I print out this example, the lines are not displayed correctly and the QR code is missing entirely.
I use this code and deliver the content of escPos to the BT printer
const printerEscPos = {
cpl: 32,
encoding: 'utf-8', // utf-8, multilingual
spacing: false,
cutting: false,
gamma: 1.0,
command: 'impact' // impact, escpos
};
const escPos = receiptline.transform(reader.result, printerEscPos);
BluetoothPrinter.connect()
.then(() => {
BluetoothPrinter.print(escPos);
});
...
print(command) {
var encoder = new TextEncoder("utf-8");
var commandEnc = encoder.encode(command + '\x0a');
console.log(commandEnc);
console.hex(commandEnc);
const maxLength = 100;
let chunks = Math.ceil(commandEnc.length / maxLength);
if (chunks === 1) {
this._queue(commandEnc);
} else {
for (let i = 0; i < chunks; i++) {
let byteOffset = i * maxLength;
let length = Math.min(commandEnc.length, byteOffset + maxLength);
this._queue(commandEnc.slice(byteOffset, length));
}
}
}
...
Here is the console output for console.log(commandEnc)
and console.hex(commandEnc)
I guess it's an ecoding problem, maybe you could give me a hint please?
Hello!
Thank you for your detailed information.
Please try to replace this part.
From
var encoder = new TextEncoder("utf-8");
var commandEnc = encoder.encode(command + '\x0a');
To
var commandEnc = Uint8Array.from(command.split('').map(c => c.charCodeAt(0)));
And the following part...
const printerEscPos = {
cpl: 32,
encoding: 'utf-8', // utf-8, multilingual
spacing: false,
cutting: false,
gamma: 1.0,
command: 'impact' // impact, escpos
};
utf-8
is an invalid value and will be replaced by cp437
.
impact
is for dot impact printers and does not support QR codes.
escpos
requires Epson TM-T88IV compatibility level, so it may not work as expected on your model.
We plan to add a generic escpos command set.
Thank you!
Hello receiptline
Thank you for your response.
I changed the encoding
to multilingual
, command
to escpos
and made the adjustment in the print method.
Now the print looks like this.
I was able to remove the A/0 characters with the two adjustments from here
The 'QR code' now also appears, but is not displayed correctly.
I'm looking forward to the planned adjustments for the generic escpos command set and thank you in advance!