Closed rizwanbao closed 2 years ago
This is a example of my code.
async urlToBase64(printer, url: string): Promise<string> {
const imageFile = await lastValueFrom(
this.http.get(url, { responseType: 'blob' })
);
const base64: string = await new Promise((resolve) => {
const reader = new FileReader();
reader.onloadend = () => {
resolve(reader.result as string);
};
reader.readAsDataURL(imageFile);
});
return await new Promise((resolve, reject) =>
ThermalPrinter.bitmapToHexadecimalString(
{
type: printer.connectionType,
id: printer.productName || printer.name,
base64
},
resolve,
reject
)
);
}
Its from angular. So in theory you can understand how it works.
Reading the file you want to print as base64 and then convert it to hex-string.
Then you can embed it in the string like:
[C]" + PrinterTextParserImg.bitmapToHexadecimalString(printer, this.getApplicationContext().getResources().getDrawableForDensity(R.drawable.logo, DisplayMetrics.DENSITY_MEDIUM))+"\n"
==
"[C]" + (await this.urlToBase64(printer, 'URL-to-Image')) + "\n"
thats great thanks
hi.. [C]" + PrinterTextParserImg.bitmapToHexadecimalString(printer, this.getApplicationContext().getResources().getDrawableForDensity(R.drawable.logo, DisplayMetrics.DENSITY_MEDIUM))+"\n" ReferenceError: PrinterTextParserImg is not defined this above code not working not getting or picking image and print can you please share some example of how to printer read the images