Advertisement
Guest User

CodeIonic

a guest
Aug 20th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. testImage(){
  2.     this.platform.ready().then(()=>{
  3.       preparaBase64('path image');
  4.       function preparaBase64(url) {
  5.         readImage(url, function (base64) {
  6.             print(base64);
  7.         });
  8.     }
  9.     function readImage(url, callback) {
  10.       console.log(url);
  11.      
  12.       var request = new XMLHttpRequest();
  13.       request.onload = function () {
  14.           var file = new FileReader();
  15.           file.onloadend = function () {
  16.               callback(file.result);
  17.           }
  18.           file.readAsDataURL(request.response);
  19.       };
  20.       request.open('GET', url);
  21.       request.responseType = 'blob';
  22.       request.send();
  23.     }
  24.    
  25.     function print(base64) {
  26.           window.BTPrinter.list(function (data1) {
  27.               window.BTPrinter.connect(function (data2) {
  28.                   console.log(data2);
  29.                   window.BTPrinter.printBase64(function (data) {
  30.                       console.log(data);
  31.                   }, function (err) {
  32.                       console.log(err);
  33.                   }, base64, '1');
  34.                   window.BTPrinter.printPOSCommand(null, null, "0A");
  35.                   window.BTPrinter.printPOSCommand(null, null, "0A");
  36.                   window.BTPrinter.printPOSCommand(null, null, "0A");
  37.                   window.BTPrinter.printPOSCommand(null, null, "0A");
  38.               }, function (err) {
  39.                   console.log(err);
  40.               }, "print name");
  41.           }, function (err) {
  42.               console.log(err);
  43.           });
  44.           window.BTPrinter.disconnect(function (data) {
  45.               console.log(data);
  46.           }, function (err) {
  47.               console.log(err);
  48.           }, "print name");
  49.       }
  50.     })
  51.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement