Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QR code not printed #9

Open
VyankeshH opened this issue Apr 10, 2018 · 19 comments
Open

QR code not printed #9

VyankeshH opened this issue Apr 10, 2018 · 19 comments
Labels

Comments

@VyankeshH
Copy link

Not able to get QR Code using this.

@ingoncalves
Copy link
Owner

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.

@VyankeshH
Copy link
Author

@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

@ingoncalves
Copy link
Owner

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

@VyankeshH
Copy link
Author

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

@ingoncalves
Copy link
Owner

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.

@VyankeshH
Copy link
Author

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

@ingoncalves
Copy link
Owner

ingoncalves commented Apr 11, 2018

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.

@shaniqwa
Copy link

shaniqwa commented May 27, 2018

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

@Blair2004
Copy link
Contributor

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

@VyankeshH
Copy link
Author

@shaniqwa Did you get solution for QR Code printing.

@shaniqwa
Copy link

@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;
  }

@VyankeshH
Copy link
Author

VyankeshH commented Aug 1, 2018

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

@shaniqwa
Copy link

shaniqwa commented Aug 1, 2018

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

@VyankeshH
Copy link
Author

VyankeshH commented Aug 2, 2018

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

@VyankeshH
Copy link
Author

@shaniqwa Thank you.I got the result.

@VyankeshH
Copy link
Author

@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

@rahuljain0114
Copy link

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

@tusharmutreja200
Copy link

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

@FazilMuhammed
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants