Setting up slip printer to print silently

From Koha Wiki
Jump to navigation Jump to search

Introduction

Tested with Koha 16.11 and Firefox 52.02, JavaScript example changed, 2017-04-09
For issues reported for Firefox 46 on Windows 7 (blank page) see partial workaround below.
For trouble shooting refer to section at the bottom of this page.

Since Koha version 3.09.00.027 it is possible to set up silent printing of circulation slips using the Firefox Add-on JSPrintSetup. The enhancement was introduced with Bug 7563.

JSPrintSetup allows e.g. to set a printer by name, to print silently, to change header and footer text, to set margins (and more). When printing is done, the previous Firefox print settings are restored. The solution works with the standard Firefox installation (no need to have a separate Firefox installation as described on the wike page Using Portable Firefox as a Koha Client.

The setup is done by overriding the standard JavaScript for slip printing with a custom JavaScript defined in the system preference 'IntranetSlipPrinterJS'. If the add-on JSPrintSetup is not installed or no JavaScript is defined in 'IntranetSlipPrinterJS', Koha behaves as before (display a print dialogue).

Reference of JSPrintSetup

Note: The solution could work with other browser plug-ins as well if they allow to do printer setup by JavaScript. If you are aware of such add-ons for Firefox or other browsers, please share.

Setup

Install and configure Firefox add-on JSPrintSetup

  • Go to the Firefox add-ons manager, search for JSPrintSetup and install
  • Important: For security reasons, the website using the add-on has to be on a list of allowed addresses. This can be configured in the Firefox add-ons manager (see Screenshot)

JavaScript for system preference 'IntranetSlipPrinterJS'

Important: The script must implement the function $( window ).load(function()
because it replaces the original function)

Note: To use Koha's standard printing routine, simply remove all JavaScript.

Note: Lines with // are 'commented out' and indicate where you could implement a more sophisticated solution. If you develop own JavaScripts, please share.

Idea for more sophisticated solution: The function jsPrintSetup.getPrintersList returns a list of installed printers. One could then check if e.g. a printer with the name "Slipprinter" is available and if yes print on this printer using jsPrintSetup.setPrinter('Slipprinter'), otherwise print to the default printer.

For full reference see: http://jsprintsetup.mozdev.org/reference.html

To edit 'IntranetSlipPrinterJS', go to Home>Administration, and type 'IntranetSlipPrinterJS' in the 'Global system preferences' search bar. Click 'click to edit' to get a text area where the following code may be copied and pasted:

Example JavaScript that silently prints (tested with Koha 16.11 / Firefox 52)

   

$( window ).load(function() {
 try
 {
    //Try to print using jsPrintSetup Plug-In in Firefox
    //If it is not installed fall back to default printing
    jsPrintSetup.clearSilentPrint();   
    jsPrintSetup.setOption('printSilent', 1);
 
    //Choose printer using one or more of the following functions
    //jsPrintSetup.getPrintersList...
    //Comment out following line to print to the default printer
    jsPrintSetup.setPrinter("PUT HERE YOUR PRINTER NAME");
 
    //Set Header and footer...
    jsPrintSetup.setOption('headerStrLeft', '');
    jsPrintSetup.setOption('headerStrCenter', '');
    jsPrintSetup.setOption('headerStrRight', '');
    jsPrintSetup.setOption('footerStrLeft', '');
    jsPrintSetup.setOption('footerStrCenter', '');
    jsPrintSetup.setOption('footerStrRight', '');
 
    jsPrintSetup.print();     
    window.close();
 }
 catch(err)
 {   
    //Default printing if jsPrintsetup is not available
    window.print();
    window.close();
 }
});




Workaround for printing blank page on Firefox 46, reported not to work under Windows 7.

jsPrintSetup prints a blank slip in Firefox 46. Was fixed by adding a delay (with setTimeout) to the script in IntranetSlipPrinterJS, like so:

   function printThenClose() {
    try
    {
      // Added delay to workaround jsPrintSetup issue with Firefox 46 - RT 34321 - 20160426.jpw
      setTimeout(function() {
      //Try to print using jsPrintSetup Plug-In in Firefox
   ...
       jsPrintSetup.print();
      window.close();
      }, 1000);
    }
    catch(err)
    {
      //Default printing if jsPrintsetup is not available


(Note, specifically, the "setTimeout(..." and "}, 1000);" lines that were added.)

Test

Go to checkout, select a patron, do 'Print slip' or 'Print quick slip' or hit button 'Check out' (with empty barcode field).

Trouble shooting

  • Using FireFox?
  • Firefox add-on JSPrintSetup installed?
  • URL defined in list of allowed sites (setup of JSPrintSetup)?
  • JavaScript defined in system preference 'IntranetSlipPrinterJS'?
  • JavaScript implements $( window ).load(function()?
  • Printer set in JavaScript?
  • Reference for JSPrintSetup with a lot of options...