img

PaperCut Print Script of the Month #12 Keyword(s) = Free Printing


As 1000’s of children march to school dressed as Maltida or a BFG we thought it a good idea to do something to honour Roald Dahl day.

This script shows off the ability to allow documents to be printed at zero cost depending on the file name. While we have gone with Roald Dahl book names, other applications could be invoice or statement depending on the customer’s needs.

The script is built around a few very simple concepts. Grab a cup of tea and we can begin.

First of all we can set an optional comment for the logs, this will help admins work out why a job ended up being zero cost.

// Comment to apply to job
var JOB_COMMENT = "Free Print Job Roald Dahl 100th Anniversary";

After that we have an array, you may remember we went into details about arrays in SOTM#3. The array in question holds a list of keywords and in this instance the keywords are Rhald Dahl’s greatest stories.

Note – All of this depends on the file name being useful, not all applications publish the file name when the send a job to the print queue. It could be that the application you print from names all print jobs the same.

// Array of Book Names
var BOOK_NAMES = [
  "The Gremlins",
  "Over To You",
  "Some Time Never",
  "Someone Like You",
  "Kiss Kiss",
  "James and the Giant Peach",
  "Charlie and the Chocolate Factory",
  "The Magic Finger",
  "Fantastic Mr Fox",
  "Charlie and the Great Glass Elevator",
  "Danny, the Champion of the World",
  "The Wonderful Story of Henry Sugar and Six More",
  "The Enormous Crocodile",
  "My Uncle Oswald",
  "The Twits",
  "George's Marvellous Medicine",
  "Revolting Rhymes",
  "The BFG",
  "Dirty Beasts",
  "The Witches",
  "Roald Dahl’s Book of Ghost Stories",
  "Boy: Tales of Childhood",
  "The Giraffe and the Pelly and Me",
  "Two Fables",
  "Going Solo",
  "Matilda",
  "Rhyme Stew",
  "Ah, Sweet Mystery of Life",
  "Esio Trot",
  "The Vicar of Nibbleswicke",
  "The Minpins",
  "Roald Dahl's Guide to Railway Safety",
  "My Year"
];

Last up we have the guts of the script. We tell the script to look at the jobname and if it matches any in the list add the comment. We used toLowerCase to work around any case sensitive problems with file names.

  // If jobname matches any of the book names
if (matchesAny(inputs.job.documentName.toLowerCase(), BOOK_NAMES.toLowerCase())) {
  // Add comment to job
  actions.job.addComment(JOB_COMMENT);

if everything matches up we set the cost to zero using the actions.job.setcost option.

// Set the cost to 0 
actions.job.setCost(0);

That is it for this month and as always the complete print script is below. If you have your own requirements for a print script and you don’t have the time or in-house experience to make it then simply contact us.

Get in touch today | sales@selectec.com

/*
* Keyword(s) = Free Printing
*
* Read more at http://selectec.com/papercut-print-script-month-12-keywords-free-printing/
*/
function printJobHook( inputs, actions ) {
  // Comment to apply to job
  var JOB_COMMENT = "Free Print Job Roald Dahl 100th Anniversary";

  // Array of Book Names
  var BOOK_NAMES = [
    "The Gremlins",
    "Over To You",
    "Some Time Never",
    "Someone Like You",
    "Kiss Kiss",
    "James and the Giant Peach",
    "Charlie and the Chocolate Factory",
    "The Magic Finger",
    "Fantastic Mr Fox",
    "Charlie and the Great Glass Elevator",
    "Danny, the Champion of the World",
    "The Wonderful Story of Henry Sugar and Six More",
    "The Enormous Crocodile",
    "My Uncle Oswald",
    "The Twits",
    "George's Marvellous Medicine",
    "Revolting Rhymes",
    "The BFG",
    "Dirty Beasts",
    "The Witches",
    "Roald Dahl’s Book of Ghost Stories",
    "Boy: Tales of Childhood",
    "The Giraffe and the Pelly and Me",
    "Two Fables",
    "Going Solo",
    "Matilda",
    "Rhyme Stew",
    "Ah, Sweet Mystery of Life",
    "Esio Trot",
    "The Vicar of Nibbleswicke",
    "The Minpins",
    "Roald Dahl's Guide to Railway Safety",
    "My Year"
  ];

  if (!inputs.job.isAnalysisComplete) {
    // No job details yet so return.
    return;
  }

  // If jobname matches any of the book names
  if (matchesAny(inputs.job.documentName.toLowerCase(), BOOK_NAMES)) {
    // Add comment to job
    actions.job.addComment(JOB_COMMENT);
    // Set the cost to 0
    actions.job.setCost(0);
  }
}

// Function borrowed from PaperCut Recipe (Confirm printing emails in color (from Outlook))
function matchesAny(str, matchStrs, actions) {
  if (str == null || matchStrs == null) {
    return false;
  }

  for (var i in matchStrs) {
    if (str.match(matchStrs[i]).toLowerCase()) {
      return true;
    }
  }

  return false;
}
Latest News from Ross Malyon
img

What card reader do I need for PaperCut MF?

Good question, my friends! Without knowing much about the customer's cards/fob...

Written by: Ross Malyon

More
img

Upgrading to PaperCut v20 from (really) old versions

Along with a host of impressive features, any new release of PaperCut MF also ...

Written by: Ross Malyon

More

img

Selectec have been a fantastic partner to Balreed with a relationship stretching back over 7 years, I can thoroughly recommend them as a forward thinking and innovative business that has a real focus on client service and support

Rory Gallagher Balreed Group
Back to Top ↑