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:
/*jshint mootools:true */ /*globals jsPrintSetup*/ (function(){ 'use strict'; // only do something if the plugin is live if ('jsPrintSetup' in this){ 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#printerList', { events: { change: function(){ Cookie.write('defaultPrinter', this.get('value'), { path: '/admin/', duration: 365 }); // save the new printer selection jsPrintSetup.setPrinter(this.get('value')); } } }); // 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 }).inject(printList); }); // needs 2 dom els: #printSetup and #goPrint printList.inject(document.id('printSetup'), 'top'); // attach an event that prints from an element called goPrint document.id('goPrint').addEvents({ click: function(){ jsPrintSetup.print(); } }); } }).call(this);
GitHub flavoured markdown enabled.