cordova-plugin-printer
cordova-plugin-printer copied to clipboard
print image
Hi! I installed the plugin and it's working fine, so i'd like know if is possible to print images too? Or generate and print QRcode? thanks!
Yes it does. You can use this to print Images cordova.plugins.printer.print('file://img/logo.png');
it's possible to use this same way to print in thermal printers bluetooth?
Yes, you can do that. Do you use any external application to print in the thermal printer?
yes my friend, I'm using bluetooth serial in ionic 4 look at my code:
async imprimir_cupom() {
const alert = await this.alertController.create({
header: 'Imprimir comprovante',
message: 'Deseja imprimir o comprovante?',
buttons: [
{
text: 'Cancelar',
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
this.router.navigate(['/menu']);
}
}, {
text: 'Sim',
handler: () => {
this.saldo_devedor_impressao = this.saldo_devedor_aconfirmar - this.exibe_valor_digitado;
let data = 'EMPRESTIMO Nº ' + this.numero_emprestimo + ' - ' + this.data_impressao + '\x0a' +
this.nome_destinatario + '\x0a' +
'Total geral R$ ' + parseFloat(this.valor_total).toFixed(2) + '\x0a' +
'Pago confirmado R$ ' + parseFloat(this.valor_pago).toFixed(2) + '\x0a' +
'Valor pago hoje R$ ' + parseFloat(this.exibe_valor_digitado).toFixed(2) + '\x0a' +
'Saldo devedor R$ ' + parseFloat(this.saldo_devedor_impressao).toFixed(2) + '\x0a' + '\x0a' + '\x0a' +
'--------------------------------' + '\x0a' +
'Consultor: ' + this.nome_user + '\x0a' +
'Atenção: O saldo devedor ainda ' + '\x0a' + ' será confirmado, obrigado!' + '\x0a' + '\x0a' + '\x0a' + '\x0a' + '\x0a' + '\x0a';
this.bluetoothSerial.write(data).then(data => {
console.log(data);
});
this.router.navigate(['/menu']);
}
}
]
});
await alert.present();
}
thank you so much my friend! could you help me?
I tried to do this way but no way, it print: [object Promise]
this.printer.isAvailable(); this.imagem = this.printer.print('
Hello World
');let data = '\x1b\x21\x10' + 'EMPRESTIMO Nº ' + this.numero_emprestimo + '\x0a' + '\x1b\x21\x00' + this.imagem; this.bluetoothSerial.write(data).then(data => { console.log(data); }); is possible to integrate your plugin with Bluetooth serial plugin?
this.printer.isAvailable().then(onSuccess=> { this.printer.print('base64://...'); }, onError=>{ alert("Error"); }); Try this way. Am sure that you will not get [object Promise] error.
no way.. I think it's happening because i print the content directly in thermal printer, and in your plugin we have a preview. the same result..