Sep 21st 2009 × jsPrintSetup: an AMAZING plugin for firefox that gives extended javascript controls to the printer
This is not a tool you can rely on for customer-facing development, but I found it invaluable nevertheless. jsPrintSetup is a small fireFox add-on that hands you a controlling object in javascript. You get FULL access to any print-related function you could think of: list printers, select default printers, print silently, control spool, headers… There’s just too much to mention. Very useful when coding a CMS that needs to print specific things to specific printers (for example, invoices on printer #1 and labels on printer #2).
Here is an example that fetches a list of printers and remembers the user’s preference for future use:
// only do something if the plugin is live
if ($type(jsPrintSetup)) {
var printers = jsPrintSetup.getPrintersList().split(","); // get a list of installed printers
// no print dialogue boxes needed
jsPrintSetup.setSilentPrint(true);
// create a dropdown
var printList = new Element("select", {
id: "printerList",
events: {
change: function() {
Cookie.write("defaultPrinter", this.get("value"), {
path: "/admin/",
duration: 365
});
// save the new printer selection
jsPrintSetup.setPrinter(this.get("value"));
}
}
}).injectTop($("printSetup"));
// get default by preference if any
var defaultPrinter = Cookie.read("defaultPrinter");
printers.each(function(el) {
new Element("option", {
value: el,
text: el,
selected: (defaultPrinter == el) ? "selected" : false
}).inject(printList);
});
// attach an event that prints from an element called goPrint
$("goPrint").addEvents({
click: function() {
jsPrintSetup.print();
}
});
}
no
no




