Closed geraldosalazar16 closed 5 years ago
This is by design, base64 images have to be loaded to the phone’s memory and create performance issues. You should get the image from the file system.
Well I really needed to print the base64 image because my image come from the database in that format. I figured out how to do it. The problem is the Ionic Native package. It turns out it only has the printImage function and not the printBase64Image from the cordova plugin. I was trying to use printImage and passing the base64 encoded string in the uri param, and that was wrong.
So all I did was use the cordova plugin instead ok the native ionic wrapper.
declare var starprnt; async printBase64Image(port: string, emulation: string, imageObj: any) { starprnt.printBase64Image(port, emulation, imageObj, result => { return result; }, error => { return error; }); }
Also, the javascript object to pass to the printBase64Image is different from the one you have to use with printImage, as I notice latter in the docs
For base64
var imageObj = { base64Image: 'put base64 image string here', width: 576 // options: 384 = 2", 576 = 3", 832 = 4" cutReceipt:true, // Defaults to true openCashDrawer:true // Defaults to true };
For printImage
var imageObj = { uri: 'file:///...', width: 576 // options: 384 = 2", 576 = 3", 832 = 4" cutReceipt:true, // Defaults to true openCashDrawer:true // Defaults to true };
Hope it helps somebody :)
Hi I have been trying to print a base64 encoded image, from an Ionic 4 app. When I use the file path of the image everything works fine, but trying the base64 encoded image just close my app without any error message.
A small code snippet to show my point
const imageObj: ImageObj = { uri: base64EncodedImage, paperWidth: 576, // options: 384 = 2", 576 = 3", 832 = 4" cutReceipt: true, // Defaults to true openCashDrawer: true // Defaults to true }; const resultPrintImage = await this.starPrinterService.printImage(printer.data.portName,printer.data.emulation, imageObj);