@joelcubero wrote:
Good morning,
I have an application developed with “ionic 4 + capacitor” and to which I need to add the functionality of printing image on a bluetooth thermal printer, I have tested with the “ionic native” printer, ble and bluetoothserial plugins and I have not achieved anything, it prints me the string literally, the image I have is in svg format and the process I do is convert the base64 string to bytes.buffer before sending it, I don’t know if I’m doing something wrong, I also tried to encode the image in png / jpg and convert base64 to bytes.buffer and print me rare characters.
I attached here the code.
Greetings and thanks
androidPrint() { const conection = this.btSerial.connect(this.selected.id).subscribe(() => { this.bytes = this.base64ToArrayBuffer(this.base64); if (this.bytes !== null && this.bytes !== '' && this.bytes !== undefined) { this.loader.presentLoader(true); this.btSerial.write(this.bytes).then(() => { this.loader.dismissLoader(); conection.unsubscribe(); }); } }, (err) => { this.loader.dismissLoader(); this.alert.presentAlert({ header: 'Error', subHeader: err.message, buttons: ['OK'] }); }); } iosPrint() { this.ble.connect(this.selected.id).subscribe(() => { this.bytes = this.base64ToArrayBuffer(this.base64); if (this.bytes !== null && this.bytes !== '' && this.bytes !== undefined) { this.loader.presentLoader(true); this.ble.write(this.selected.id, '18F0', '2AF1', this.bytes).then( () => { this.loader.dismissLoader(); }, (err) => { this.loader.dismissLoader(); this.alert.presentAlert({ header: 'Error', subHeader: err.message, buttons: ['OK'] }); } ); } }, (err) => { this.loader.dismissLoader(); this.alert.presentAlert({ header: 'Error', subHeader: err.message, buttons: ['OK'] }); }); }
// Create buffer from base64 base64ToArrayBuffer(base64) { const cadena = atob(base64); const bytes = new Uint8Array(cadena.length); for (let i = 0; i < cadena.length; i++) { bytes[i] = cadena.charCodeAt(i); } return bytes.buffer; }
I hope you see answer
Posts: 1
Participants: 1