0

I'm trying to build ionic print app using BluetoothSerial plugin to print image. I convert (base64) image to Uint8Array before send to printer. but I got nothing. please help me to print image. Uint8Array

SKdlg
  • 1
  • 1
  • what is the printer that you are using (link to documentation please) also are able to print image son it using the ready made samples? – user16930239 Oct 01 '21 at 23:46

1 Answers1

0

I've tried this method a long ago but I couldn't make it work correctly but I was able to do it using cordova-plugin-datecs-printer which allow you to print the image after converting it to base64 like this:

function printMyImage() {
  var image = new Image();
  image.onload = function() {
      var canvas = document.createElement('canvas');
      canvas.height = 100;
      canvas.width = 100;
      var context = canvas.getContext('2d');
      context.drawImage(image, 0, 0);
      var imageData = canvas.toDataURL('image/jpeg').replace(/^data:image\/(png|jpg|jpeg);base64,/, ""); //remove mimetype
      window.DatecsPrinter.printImage(
          imageData, //base64
          canvas.width, 
          canvas.height, 
          1, 
          function() {
            alert('Success');
          },
          function(error) {
              alert(JSON.stringify(error));
          }
      )
  };
  image.src = 'img/some_image.jpg';
}

you can check all the details and how to connect the printer from the documentation here

Louay Sleman
  • 1,794
  • 2
  • 15
  • 39