Open VyankeshH opened 6 years ago
You must make sure if your printer supports the full ESC/POS protocol, and also check if the size of the data you're printing is in an acceptable range by the printer.
@ingoncalves I got result with barcode but I get that String when I am trying to print QRCode of that respected String.Also I check the features of my Printer It support ESC/POS protocol.Then what is the issue I didn't understand
@VyankeshH try doing this:
import { EscPos } from '@datahex/escpos-xml';
const xml = `
<?xml version="1.0" encoding="UTF-8"?>
<document>
<qrcode ecl="M">{{qrcode}}</qrcode>
</document>
`;
const data = {
qrcode: 'hello qrcode'
};
const buffer = EscPos.getBufferFromTemplate(xml, data);
// send this buffer to the printer
Thus, we are going to eliminate other hypotheses of error. Please, report me the result.
@ingoncalves If I used above code then my Output on printer will be : hello qrcode
Well, in this case, I think that your printer doesn't support the QR code feature. Unfortunately, there are some models that don't support it. You should check your printer specifications.
@ingoncalves OK Brother,Actually I checked all specification. It showing for the QRcode supported
Hmm, it's weird. So, you may use the BufferBuilder or try writing the buffer manually, according to the printer specification. There might be differences in protocol.
having the same issue, with CITIZEN CT-S310II printer which support QR printing.
have tried EscPos.getBufferBuilder().printQRcode(data)
. all I get is the data printed instead of QR :\
any help would be much appreciated. btw great project..!
I've tested as well with my printer, EPSON TM-T20II and it support the barcode and Qr Code.
@shaniqwa Did you get solution for QR Code printing.
@VyankeshH I have implemented this function with some help from node-thermal-printer
/**
*
* @param code - string of the QR code
* @param version - QR model: number 1, 2
* @param level - correction level: L - 7%, M - 15%, Q - 25%, H - 30%
* @param size - QR size, number between 1 - 16
* @returns {Array}
*/
static printQR(code: string, version?: number, level?: string, size?: number): any[] {
const buffer: any[] = [];
// center the QR Code
buffer.push(...config.TXT_ALIGN_CT);
buffer.push(...config.HW_SELECT);
// [Name] Select the QR code model
// [Code] 1D 28 6B 04 00 31 41 n1 n2
// n1
// [49 x31, model 1]
// [50 x32, model 2]
// [51 x33, micro qr code]
// n2 = 0
if (version) {
if (version === 1) {
buffer.push(...config.QRCODE_MODEL1);
} else {
buffer.push(...config.QRCODE_MODEL2);
}
} else {
buffer.push(...config.QRCODE_MODEL2);
}
// [Name]: Set the size of module
// 1D 28 6B 03 00 31 43 n
// n depends on the printer
if (size) {
const command: string = 'QRCODE_CELLSIZE_'.concat(size.toString());
buffer.push(...config[command]);
} else {
buffer.push(...config.QRCODE_CELLSIZE_3);
}
// [Name] Select the error correction level
// 1D 28 6B 03 00 31 45 n
// n
// [48 x30 -> 7%]
// [49 x31-> 15%]
// [50 x32 -> 25%]
// [51 x33 -> 30%]
if (level) {
const command: string = 'QRCODE_CORRECTION_'.concat(level.toUpperCase());
buffer.push(...config[command]);
} else {
buffer.push(...config.QRCODE_CORRECTION_M);
}
// [Name] Store the data in the symbol storage area
// 1D 28 6B pL pH 31 50 30 d1...dk
const s: number = code.length + 3;
const pL: number = Math.floor(s % 256);
const pH: number = Math.floor(s / 256);
buffer.push(...[0x1d, 0x28, 0x6b, pL, pH, 0x31, 0x50, 0x30]);
// convert Buffer to array
const codeBuf: Buffer = new Buffer(code);
const codeArr = Array.prototype.slice.call(codeBuf, 0);
buffer.push(...codeArr);
// buffer.push(...new Buffer((pL + pH * 256) - 3)); // CITIZEN PRINTER ONLY
// [Name] Print the symbol data in the symbol storage area
// 1D 28 6B 03 00 31 51 m
buffer.push(...config.QRCODE_PRINT);
return buffer;
}
@shaniqwa I tried this also still I got Chinese characters on print.My printer name is FUKUN pos80 printer.
@VyankeshH you have to follow your printer's guide for QR printing and change the commands if needed. each printer is a bit different, this code works for CITIZEN printer. I have downloaded an ugly pdf with all printers commands and followed it, eventually it worked.
@shaniqwa Can you show me the return data? Is it possible for you now??
@shaniqwa Thank you.I got the result.
@shaniqwa @ingoncalves How could I merge two buffer for printing purpose. first buffer is XML and second buffer is QRCode buffer.I want to print first buffer on left side of the page and second buffer on the Right side of the page.Any help would be much appreciated
@VyankeshH I am facing the same problem. Could you help me how you implemented @shaniqwa solution.
I am also facing the same issue, is there any update
@VyankeshH I have base64 data is it possible to get qrcode
Not able to get QR Code using this.