Created
January 6, 2015 23:44
-
-
Save jwoertink/fa93ecf9e5b4ec13d97c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<a href="#" onclick="process.mainModule.exports.printer()">Click to print</a> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ipp = require("ipp"), | |
PDFDocument = require("pdfkit"); | |
module.exports.printer = function() { | |
var doc = new PDFDocument({margin:0}); | |
doc.text("Hello World", 100, 100); | |
var printerName = 'Lanier_MP_3500'; // The name of your printer on your network | |
var printer = ipp.Printer("http://localhost:631/printers/"+printerName); | |
var buffers = []; | |
doc.on('data', buffers.push.bind(buffers)); | |
doc.on('end', function () { | |
var file = { | |
"operation-attributes-tag":{ | |
"requesting-user-name": "User", | |
"job-name": "Print Job", | |
"document-format": "application/pdf" | |
}, | |
data: Buffer.concat(buffers) | |
}; | |
printer.execute("Print-Job", file, function (err, res) { | |
window.console.log("Printed: "+res.statusCode); | |
}); | |
}); | |
doc.end(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"main": "index.html", | |
"node-main": "index.js", | |
"name": "node-webkit-print-example", | |
"description": "sample setup for printing without dialog from node-webkit", | |
"dependencies": { | |
"ipp": "0.0.6", | |
"pdfkit": "^0.7.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment