Is it that hard to print in a thermal printer?

Hello,

I’m currently developing an app where you generate a label in format PDF (I store it in base64 on the database), and then I want to print directly that document in a thermal printer (Zebra D420).

I made a really hard research and I tried a lot, but nothing worked for me. I tried integrate with the API of Zebra but they don’t print PDFs throught the API, also tried a couple of cordova plugins but also never achieve to work… Currently I’m trying to print through bluetooth but I’m struggilng to print the PDF instead of plain text.

I just wanted to know if is that hard to print a PDF in a thermal print because when I do it on Chrome is so easy and also Zebra has an applicattion where you can print what ever you want. Why I can’t send a ByteArray or something to the printer through the IP and Port and print? Will be so easy and awesome.

Any ideas to print PDFs in the app to the thermal printer? The easiest way… also if you have any reference project or something.

I have a similar project for thermal printer, but to print text, image and bar code, however at the moment I am managing to print only text.

For print you can use BluetoothSerial ( https://ionicframework.com/docs/native/bluetooth-serial )

Hi alysson,

My project is probably the same, I need to print labels that I have on PDF format.

I will take a look at BluetoothSerial, If you achieve to print images on your thermal print let me know :smiley: .
Thanks and Good Luck!!!

I have done a bunch of Cordova applications which output CPCL (similar to ZPL) which worked really well.

I never attempted PDF as it is not a great idea…

The interfaces are often pretty slow so outputting something takes ages compared to CPCL (and I did include images)

CPCL / ZPL quality is as perfect as it gets.

If you’re interested in some plugins I did reply back

1 Like

Thanks for your answer @Judgewest2000,

Well I have the PDF Labels in Base64 so maybe there’s a way to parse them to CPCL or ZPL, I would like to see any examples of what you did to get ideas to resolve my issue or find a way to do it.

Also tell me the plugins you used it. Thanks in advance :smiley:

Hola Gonzalo,
Al igual que tu, llevo luchando casi 2 semanas con una impresora portable bluetooth ( GOOJPRT )
Y con el cordova-plugin-bluetooth-serial pude conectar y con no poco esfuerzo imprimir un ticket y su código de barras.
Pero el problema es que solo he logrado conectarme con Android de celulares Samsung (… muy raro…)
Intenté subir imagenes, o un PDF pero eso fue imposible, la documentación es pobre y además la gente de IONIC pareciera no estar en la “onda de imprimir”.
Si necesitas ayuda, en lo que pueda ayudar, solo me avisas.
Saludos

Hi Gonzalo,
Like you, I have been struggling for almost 2 weeks with a portable bluetooth printer (GOOJPRT)
And with the cordova-plugin-bluetooth-serial I was able to connect and with no little effort print a ticket and its barcode.
But the problem is that I have only managed to connect with Android from Samsung cell phones (… very strange…)
I tried to upload images, or a PDF but that was impossible, the documentation is poor and also the people at IONIC seem not to be in the “printing wave”.
If you need help, in what I can help, just let me know.
Greetings

Buenos días @jgv66 ,

Gracias por tu respuesta, al igual que tu llevo peleandome con las impresoras bluetooth un tiempo, intente utilizar el cordova-plugin-bluetooth-serial, pero no me llegó a servir ya que yo necesitaba obligatoriamente imprimir una etiqueta en PDF, mi solución ha sido utilizar este plugin https://github.com/CesarBalzer/Cordova-Plugin-BTPrinter , he conseguido imprimir una imagen pasandola a base64 y llamando al método que tiene de printBase64, te recomiendo probarlo, si tienes algún problema me dices.

Un saludo.

Good Morning,

I finally achieve it. I found a cordova plugin made by a guy that was so easy to connect to the Bluetooth Printer, then I saw someone forked it and created the functionality of print Base64 format so I decide to try it and I printed my first image in the thermal printer.

The plugin that I used is this:

Hola jgv66
Ahora mismo estoy en el mismo problema, buscando como imprimir en una Impresora Zebra, pero también no entiendo el porque la gente de IONIC están lejos del estos procesos, si pudieras apoyarme seria de gran ayuda, justo ayer empecé a probar con el plugin cordova-plugin-bluetooth-serial pero estoy un poco perdido ya que no logro imprimir, de antemano muchas gracias.

Gonzalo,
Gracias por tu respuesta. Yo estoy trabajando en Ionic 5 con Capacitor.
¿Cómo lo usas para incorporarlo en tu proyecto ? ¿Algún comando especial ? ¿Tienes algún ejemplo aunque sea básico ?
Saludos y gracias de antenamo

Buenas @makgustavo

Resulta que las pruebas que yo estaba realizando las hacía en una impresora con BlueTooth normal y funcionaban pero luego cuando fui a probar en la impresora Zebra no me funcionaba y encontré que es porque la impresora que tengo (Zebra ZD420) funciona con Bluetooth LE y al parecer no puedo realizar la conexión por el Socket de Bluetooth normal… Sigo trabajando en ello, puedes echarle un ojo al plugin que está puesto como respuesta si tu impresora contiene Bluetooth normal.

Un saludo

Buenas @jgv66

Lo siento pero aún no he trabajado con Capacitor, desconozco que plugins tiene o si puedes usar los de cordova igual. Siento no poder ayudarte.

Un saludo

Gracias. @gonzalo.paniagua

Después de una semana logre imprimir en una ZEBRA ZQ320 con el plugin nativo de IONIC (Bluetooth Serial) ahora solo estoy peleando con el lenguaje ZPL para acomodar el ticket y las imágenes y ver como llevar las variables al ticket, no he confirmado si se puede enviar directo un PDF, que es creo lo que tu requieres pero si por alguna razón lo veo te aviso para que pruebes.

Excelente inicio de semana.

2 Likes

Hola jgv66 estoy intentando implementar la impresion ionic 4 y ya logre imprimir solo texto sin estilo! queria que me ayudaras diciendome como le agregaste el estilo a tus tickets

gracias

Hola Albert
Este es el codigo que usé para imprimir el recibo, si requieres algo mas explicado me indicas
Saludos

construirRecibo( item ) {
// console.log(item);
let receipt = ‘’;
receipt += commands.HARDWARE.HW_INIT;
receipt += commands.TEXT_FORMAT.TXT_4SQUARE + commands.TEXT_FORMAT.TXT_ALIGN_CT + commands.TEXT_FORMAT.TXT_BOLD_ON;
receipt += ‘HVC CARGO’;
receipt += commands.EOL + commands.EOL;
receipt += ‘>>>> ’ + item.id_paquete.toString() + ’ <<<<’ ;
receipt += commands.EOL + commands.EOL;
receipt += commands.TEXT_FORMAT.TXT_ITALIC_OFF + commands.EOL + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.TEXT_FORMAT.TXT_NORMAL;
// hasta aqui grande, ahora normal
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT ;
receipt += ‘Retirador:’ + commands.TEXT_FORMAT.TXT_BOLD_ON + this.datos.nombre + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += commands.HORIZONTAL_LINE.HR3_58MM + commands.EOL;
// --------
receipt += commands.TEXT_FORMAT.TXT_2WIDTH + commands.TEXT_FORMAT.TXT_ALIGN_CT + commands.TEXT_FORMAT.TXT_BOLD_ON;
receipt += ‘ORIGEN’ ;
receipt += commands.TEXT_FORMAT.TXT_NORMAL + commands.TEXT_FORMAT.TXT_ALIGN_LT + commands.EOL + commands.EOL;
receipt += 'Cliente: ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.cli_razon + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Direcc.: ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.cli_direccion + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Comuna : ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.cli_comuna + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Bultos : ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.bultos.toString() + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Peso : ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.peso.toString() + ‘Kg.’ + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Volumen: ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.volumen.toString() + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Fono : ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.cli_fono1 + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += commands.HORIZONTAL_LINE.HR3_58MM + commands.EOL;
// --------
receipt += commands.TEXT_FORMAT.TXT_2WIDTH + commands.TEXT_FORMAT.TXT_ALIGN_CT + commands.TEXT_FORMAT.TXT_BOLD_ON;
receipt += ‘PAGO’ ;
receipt += commands.TEXT_FORMAT.TXT_NORMAL + commands.TEXT_FORMAT.TXT_ALIGN_LT + commands.EOL + commands.EOL;
receipt += 'Pago : ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.tipo_pago + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Tipo : ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.desc_pago + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Cobrar : ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + ‘$’ + item.valor_cobrado.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, ‘$1,’) + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += commands.HORIZONTAL_LINE.HR3_58MM + commands.EOL;
// --------
receipt += commands.TEXT_FORMAT.TXT_2WIDTH + commands.TEXT_FORMAT.TXT_ALIGN_CT + commands.TEXT_FORMAT.TXT_BOLD_ON;
receipt += ‘DESTINO’ ;
receipt += commands.TEXT_FORMAT.TXT_NORMAL + commands.TEXT_FORMAT.TXT_ALIGN_LT + commands.EOL + commands.EOL;
receipt += 'Destinat.: ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.des_razon + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Direccion: ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.des_direccion + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Comuna : ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.des_comuna + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += 'Fonos : ’ + commands.TEXT_FORMAT.TXT_BOLD_ON + item.des_fono1 + commands.TEXT_FORMAT.TXT_BOLD_OFF + commands.EOL;
receipt += commands.HORIZONTAL_LINE.HR3_58MM + commands.EOL + commands.EOL;
// code39
// receipt += commands.TEXT_FORMAT.TXT_ALIGN_CT; // Select justification: Centering
// receipt += ‘\x1d\x68\x50’; // Set barcode height: in case TM-T20, 6.25 mm (50/203 inches)
// receipt += ‘\x1d\x48\x02’; // Select print position of HRI characters: Print position, below the barcode
// receipt += ‘\x1d\x66\x01’; // Select font for HRI characters: Font B
// receipt += ‘\x1d\x6b\x04’; // Print barcode: (A) format, barcode system = CODE39
// receipt += item.id_paquete.toString();
// receipt += ‘\x00’;
// receipt += commands.EOL;
// receipt += commands.EOL;

// receipt += commands.TEXT_FORMAT.TXT_ALIGN_CT; // Select justification: Centering
// receipt += ‘\x1d\x68\x50’; // Set barcode height: in case TM-T20, 6.25 mm (50/203 inches)
// receipt += ‘\x1d\x48\x02’; // Select print position of HRI characters: Print position, below the barcode
// receipt += ‘\x1d\x66\x00’; // Select font for HRI characters: Font B
// receipt += ‘\x1d\x6b\x04’; // Print barcode: (A) format, barcode system = CODE39
// receipt += item.id_paquete.toString();
// receipt += ‘\x00’;
// receipt += commands.EOL;
// receipt += commands.EOL;

receipt += commands.TEXT_FORMAT.TXT_ALIGN_CT; // Select justification: Centering
receipt += ‘\x1d\x68\x50’; // Set barcode height: in case TM-T20, 6.25 mm (50/203 inches)
receipt += ‘\x1d\x77\x03’; // Set barcode width
receipt += ‘\x1d\x48\x02’; // Select print position of HRI characters: Print position, below the barcode
receipt += ‘\x1d\x66\x02’; // Select font for HRI characters: Font B
receipt += ‘\x1d\x6b\x04’; // Print barcode: (A) format, barcode system = CODE39
receipt += item.id_paquete.toString();
receipt += ‘\x00’;
receipt += commands.EOL;
receipt += commands.EOL;

/*
'// — Print barcode39 —>>>
'// Select justification: Centering
ESC “a” 1
“<< Bonus points : 14 >>”
'// Print and feed paper: Paper feeding amount = 4.94 mm (35/180 inches)
ESC “J” 35
'// Set barcode height: in case TM-T20, 6.25 mm (50/203 inches)
GS “h” 50
'// Select print position of HRI characters: Print position, below the barcode
GS “H” 2
'// Select font for HRI characters: Font B
GS “f” 1
'// Print barcode: (A) format, barcode system = CODE39
GS “k” 4 “00014” 0
'// — Print barcode —<<<
*/

/**

  • QRCode Assembly into ESC/POS bytes.
1 Like

muchas gracias Jjgv66

Hola Albert, me han regalado una impresora Bluetooth LE “GOOJPRT” de 58mm.
He desarrollado una App en Ionic 4 y he conseguido conectar con ella, pero no sé como enviarle información para que la imprima. ¿Podrías ayudarme diciéndome cómo lo hiciste?

Gracias de antemano.

Raúl

Hola! Buenas noches he intentado con: https://github.com/CesarBalzer/Cordova-Plugin-BTPrinter - pero no se como utilizar esta variable: BTPrinter

declare var BTPrinter: any;

No funciona.

declare var window;

window.BTPrinter...

Tampoco

import BTPrinter from 'cordova-plugin-btprinter';

Ya estoy un poco desesperado, quisiera saber como lo hiciste, porque yo puedo imprimir texto, codigos de barra, (con el bluetooth-serial) pero necesito imprimir qrCode, una imagen tipo logo. Nada que lo logro, la llibrería que indicas es la que más se parece a lo que necesito, pero no logro utilizar la variable BTPrinter .

1 Like

Disculpa carnal por la tardansa, lo resolvi con esta pagina
https://levelup.gitconnected.com/how-to-print-on-a-bluetooth-printer-using-your-ionic-application-ceabc45abf75