cordova-plugin-printer icon indicating copy to clipboard operation
cordova-plugin-printer copied to clipboard

print image

Open ademir10 opened this issue 5 years ago • 7 comments

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!

ademir10 avatar Nov 24 '19 21:11 ademir10

Yes it does. You can use this to print Images cordova.plugins.printer.print('file://img/logo.png');

vishwas097 avatar Dec 10 '19 10:12 vishwas097

it's possible to use this same way to print in thermal printers bluetooth?

ademir10 avatar Dec 10 '19 14:12 ademir10

Yes, you can do that. Do you use any external application to print in the thermal printer?

vishwas097 avatar Dec 10 '19 14:12 vishwas097

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?

ademir10 avatar Dec 10 '19 14:12 ademir10

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?

ademir10 avatar Dec 10 '19 20:12 ademir10

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.

vishwas097 avatar Dec 11 '19 04:12 vishwas097

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..

ademir10 avatar Dec 11 '19 14:12 ademir10