esc-pos-encoder-ionic-demo icon indicating copy to clipboard operation
esc-pos-encoder-ionic-demo copied to clipboard

Problem trying print with image [Bluetooth printer]

Open mariapaulinar opened this issue 4 years ago • 0 comments

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.

mariapaulinar avatar Dec 14 '20 02:12 mariapaulinar