escpos-xml icon indicating copy to clipboard operation
escpos-xml copied to clipboard

QR code not printed

Open VyankeshH opened this issue 6 years ago • 19 comments

Not able to get QR Code using this.

VyankeshH avatar Apr 10 '18 07:04 VyankeshH

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 avatar Apr 10 '18 22:04 ingoncalves

@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 avatar Apr 11 '18 10:04 VyankeshH

@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 avatar Apr 11 '18 12:04 ingoncalves

@ingoncalves If I used above code then my Output on printer will be : hello qrcode

VyankeshH avatar Apr 11 '18 13:04 VyankeshH

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 avatar Apr 11 '18 14:04 ingoncalves

@ingoncalves OK Brother,Actually I checked all specification. It showing for the QRcode supported

VyankeshH avatar Apr 11 '18 14:04 VyankeshH

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.

ingoncalves avatar Apr 11 '18 14:04 ingoncalves

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..!

shaniqwa avatar May 27 '18 12:05 shaniqwa

I've tested as well with my printer, EPSON TM-T20II and it support the barcode and Qr Code.

Blair2004 avatar Jul 20 '18 01:07 Blair2004

@shaniqwa Did you get solution for QR Code printing.

VyankeshH avatar Jul 31 '18 08:07 VyankeshH

@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 avatar Jul 31 '18 12:07 shaniqwa

@shaniqwa I tried this also still I got Chinese characters on print.My printer name is FUKUN pos80 printer.

VyankeshH avatar Aug 01 '18 10:08 VyankeshH

@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 avatar Aug 01 '18 10:08 shaniqwa

@shaniqwa Can you show me the return data? Is it possible for you now??

VyankeshH avatar Aug 02 '18 09:08 VyankeshH

@shaniqwa Thank you.I got the result.

VyankeshH avatar Aug 02 '18 09:08 VyankeshH

@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 avatar Aug 07 '18 07:08 VyankeshH

@VyankeshH I am facing the same problem. Could you help me how you implemented @shaniqwa solution.

rahuljain0114 avatar Aug 22 '18 10:08 rahuljain0114

I am also facing the same issue, is there any update

tusharmutreja200 avatar Feb 15 '21 13:02 tusharmutreja200

@VyankeshH I have base64 data is it possible to get qrcode

FazilMuhammed avatar Dec 28 '21 10:12 FazilMuhammed