我正在使用这个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] });
});
});
我想知道如何在没有任何弹出窗口的情况下直接打印到打印机。
答案 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);
});