如何在没有任何弹出选项的情况下直接从iPad打印cordova打印插件?

时间:2016-12-11 10:36:01

标签: ios cordova ionic-framework phonegap-plugins

我正在使用这个cordova插件: https://github.com/katzer/cordova-plugin-printer

  $ionicPlatform.ready().then(function () {

    var printerId = $scope.printData.printerUrl;
    alert('print to: ' + printerId);

    cordova.plugins.printer.pick(function(printerId) {
      cordova.plugins.printer.print("<p>TEST PRINT</p>", { printerId: printerId, bounds:[20, 20, 0, 0] });

    });
});

我想知道如何在没有任何弹出窗口的情况下直接打印到打印机。

1 个答案:

答案 0 :(得分:1)

使用ng-cordova打印机,此代码可直接打印到打印机。 确保您有正确的打印机网址。像“ipp://192.168.../ipp”

这样的东西
var htmlContent = "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>Title</title> <link href='css/print.css' rel='stylesheet' /></head><body><div>test print</div></body></html>"

      var options = {
          name: 'print-job', // printjob name
          printerId: $scope.PrinterUrl, // network url of the printer to use (iOS only)
          //duplex: false, // default true (double sided) (iOS only)
          landscape: false, // default false (portrait)
          graystyle: true, // prints black and white (default), but true has better performance
          bounds: {left:0, top:0, width:0, height:0}, // size and position of the print view (iPad only)
          hidePaperFormat: true,
          border: false,
          hidePageRange: true
        };

      $cordovaPrinter.print(htmlContent, options).then(function(msg){
        console.log('Print Ok: ' + msg);
      });