如何将页面的屏幕截图打印到蓝牙打印机

时间:2017-06-26 19:14:04

标签: ionic-framework printing bluetooth screenshot

目前正在使用srehanuddin Cordova-Plugin-Bluetooth-Printer。我首先截取页面的截图,将其URI保存在base64中尝试打印该数据但是打印机(京普蓝牙打印机)似乎没有解释数据,因为它打印了一些无法读取的内容。如何拍摄屏幕再打印?

这是我的代码,

 printScreenShot() {
let alert = this.alertCtrl.create();
alert.setTitle('Print');
alert.addInput({
  type: 'radio',
  label: 'Bluetooth',
  value: 'bt'
});
alert.addInput({
  type: 'radio',
  label: 'Other',
  value: 'other'
});

alert.addButton('Cancel');
alert.addButton({
  text: 'OK',
  handler: data => {
    console.log(data);
    if (data == 'bt') {
      this.printVisible = false;
      this.backVisible = false;
      this.screenshot.URI(80).then(res => {
        console.log(res);
        console.log(res.URI);
        this.printBluetooth(res.URI);
      }, err => {
        this.printVisible = true;
        this.backVisible = true;
      });
    } else {
      this.backVisible = false;
      this.printVisible = false;
      this.screenshot.URI(80).then(res => {
        this.printOther(res.URI);
      }, err => {
        this.printVisible = true;
        this.backVisible = true;
      });
    }
  }
});
alert.present();

}

 printBluetooth(URI) {
BTPrinter.list(data => {
  console.log(data);
  if (data) {
    let alert = this.alertCtrl.create();
    alert.setTitle('Paired Devices');
    for (let device of data) {
      alert.addInput({
        type: 'radio',
        label: device,
        value: device
      });
    }


    alert.addButton('Cancel');
    alert.addButton({
      text: 'OK',
      handler: data => {
        this.printBt(URI, data);
      }
    });
    alert.present();
  } else {
    this.global.toast('Error occured', 'toast-error');
    this.backVisible = true;
    this.printVisible = true;
  }
})

}

printBt(URI, mac) {
console.log(mac);
let loader_send_1 = this.global.presentLoader('Sending ...');
loader_send_1.present();
BTPrinter.connect(function (mac) {
  console.log(mac);
  BTPrinter.print(function (data) {
    console.log("Success");
    console.log(data)
  }, function (err) {
    console.log("Error");
    console.log(err)
  }, URI)

}, function (err) {
  this.global.toast(err, 'toast-error');
  console.log(err)
}, mac);

}

<button (click)="printScreenShot()" ion-fab>

0 个答案:

没有答案