Code Monkey home page Code Monkey logo

esc-pos-encoder-ionic-demo's Introduction

ESC Pos Encoder Demo (Ionic 5)

A simple ionic 5 demo application to show printing capability into thermal printer by sending a byte code stream into the printer.

Notes

  • Only works on Android / iOS device
  • Tested on Epson thermal printer TM-T82
  • Works on:
    • Bluetooth connection
    • Ethernet connection

Library

Guide

  • git clone https://github.com/Ans0n-Ti0/esc-pos-encoder-ionic-demo
  • navigate into project folder
  • npm install
  • ionic cordova platform add android
  • ionic cordova run android

esc-pos-encoder-ionic-demo's People

Contributors

ansontio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

esc-pos-encoder-ionic-demo's Issues

Problem trying print with image [Bluetooth printer]

Hello everyone.

I have been trying to print a receipt using this package to send the data to the printer, however when I try to print with an image it is not working properly, the printer stops at a certain point and does not keep printing. This is my code:

  var impresora = this.printerService;
  const encoder = new EscPosEncoder();
  let img = new Image();
  img.src = 'assets/imgs/colsaisa3.png';
  img.onload = function () {
    const encoder = new EscPosEncoder();
    let result = encoder
      .codepage('cp852')
      // .newline()
      .image(img, 120, 120, 'atkinson')
      .newline()
      .newline()
      .align('center')
      .line('Recibo de caja')
      .line(resp.id)
      .newline()
      .newline()
      .align('left')
      .line('CLIENTE: ' + resp.cliente)
      .line('IDEN: ' + resp.iden)
      .line('FECHA: ' + resp.fecha)
      .line('VENDEDOR: ' + resp.vendedor)
      .newline()
      .newline()
      .bold(true)
      .line('FACTURA     SALDO        PAGO')
      .bold(false);
    for (const item of resp.facturas) {
      const cantFactura = (item.numeroFactura.toString().length <= 11) ? 11 - item.numeroFactura.toString().length : 0;
      const cantSaldo = (formatNumber(item.saldo, 'en-US').length <= 11) ? 11 - formatNumber(item.saldo, 'en-US').length : 0;
      const cantPago = (formatNumber(item.valorConsignar, 'en-US').length <= 11) ? 11 - formatNumber(item.valorConsignar, 'en-US').length : 0;
      const line = item.numeroFactura + ' '.repeat(cantFactura) + ' $' + formatNumber(item.saldo, 'en-US') + ' '.repeat(cantSaldo) + ' $' + formatNumber(item.valorConsignar, 'en-US') + ' '.repeat(cantPago);
      // console.log({cantFactura, cantSaldo, cantPago, line});

      result = result.line(line);
    }
    result = result
      .line('-------------------------------')
      .line('TOTAL PAGADO ' + resp.totalPagado)
      .newline()
      .newline()
      .line('Formas Pago')
      .line('-------------------------------');
    for (const item of resp.formasPago) {
      result = result.line(item.tipo + '   $' + item.valor);
    }
    result = result
      .line('-------------------------------')
      .line('TOTAL PAGADO ' + resp.totalPagado)
      .newline()
      .line('Estimado cliente.')
      .line('Su pago lo podrá ver reflejado')
      .line('en el portal de clientes')
      .line('www.tiendacolsaisa.com')
      .line('en las próximas 48 horas.')
      .newline()
      .line('Recuerde que los descuentos por')
      .line('pronto pago sólo son')
      .line('aplicados si usted se encuentra')
      .line('al día en cartera.')
      .newline()
      .bold(true)
      .line('Gracias por preferir a COLSAISA.')
      .bold(false)
      .newline()
      .newline()
      .encode();
    // console.log({ result });
    impresora.imprimirEnImpresoraBluetooth(item.id, result);

The funny thing about all this is that if I comment on the line where I use the image, the receipt prints completely.

I attach some videos where you can see the behavior. The first is when the image is used and the second is when I comment the line where the image is used:

  1. https://youtu.be/9hh5Y9gjEaQ
  2. https://youtu.be/ht_6EegPWU4

Can anyone give me an idea why you may be presenting this and how to fix it?

Thank you very much for your help.

Beeper Sound function

hi
may i know is there a "Beeper" Sound function?

i found some resource for the command for those who need can find from below link :

https://github.com/stefanosbou/esc-pos-java/blob/master/src/main/java/io/github/escposjava/print/Commands.java
https://github.com/escpos/escpos/blob/master/lib/escpos.rb

For those who want to add into the plugin can add below code into esc-pos-encoder.js

beeper() {
    this._queue([
        0x1b,0x42,0x05,0x01
    ]);

    return this;
}

cashdrawer() {
    this._queue([
        0x1b,0x70,0x00
    ]);

    return this;
}

Page cannot access when use "esc-pos-encoder-ionic"

Hi, I try to use "esc-pos-encoder-ionic" NPM package in my Ionic project.
When I try to open the page which use the service contains the imported library I have this error:

ERROR Error: Uncaught (in promise): ReferenceError: Cannot access 'HomePageModule' before initialization
ReferenceError: Cannot access 'HomePageModule' before initialization

Related code:

import EscPosEncoder from 'esc-pos-encoder-ionic';
//----
createTicket(){
const encoder = new EscPosEncoder();
const result = encoder.initialize();

result
  .align('center')
  .newline()
  .line('Congratulation, print success')
  .line('IP : ' + '192.168.1.1')
  .line('Port : ' + '9100')
  .newline()
  .newline()
  .newline()
  .newline()
  .newline()
  .newline()
  .cut();

const resultByte = result.encode();

// send byte code into the printer
socket.open(
  '192.168.1.1',
  '9100',
  () => {
    socket.write(resultByte, () => {
      socket.shutdownWrite();
    });
  },
  (err) => {
    console.error(err);
  }
);

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.