Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Created January 6, 2015 23:44
Show Gist options
  • Save jwoertink/fa93ecf9e5b4ec13d97c to your computer and use it in GitHub Desktop.
Save jwoertink/fa93ecf9e5b4ec13d97c to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<a href="#" onclick="process.mainModule.exports.printer()">Click to print</a>
</body>
</html>
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();
};
{
"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