Search code examples
ioscordovaionic-frameworkphonegap-plugins

How to print directly from iPad without any popup options in cordova print plugin?


Im using this cordova plugin: 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] });

    });
});

I want to know how to print directly to printer without any popup.


Solution

  • Using ng-cordova printer, this code prints directly to printer. Make sure you have correct printer url. something like "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);
          });