Jump to content

Recommended Posts

Posted

Hi Guys,

 

I am trying to write a script (my first one!) for papercut to prompt our users if the print job is colour to confirm they would like to print the document or convert it to greyscale. I have this script but I don't know why it keeps on printing in colour no matter if you click yes or no... is anybody able to look at what I have done wrong please?

 

 /*
* Color print jobs require user confirmation
*
* Color printing is expensive so users should be encouraged to print
* in grayscale whenever they print in color. No confirmation is required
* for grayscale jobs.
*/
function printJobHook(inputs, actions) {
 /*
 * This print hook will need access to all job details
 * so return if full job analysis is not yet complete.
 * The only job details that are available before analysis
 * are metadata such as username, printer name, and date.
 *
 * See reference documentation for full explanation.
 */
 if (!inputs.job.isAnalysisComplete) {
   // No job details yet so return.
   return;
 }
 
 // Test if the job is color (contains at least 1 color page)
 if (inputs.job.isColor) {
   // Add your action code here
   var response = actions.client.promptYesNo("This print job is color"
                                             + " and costs " + inputs.utils.formatCost(inputs.job.cost)
                                             + ".  You can save money by printing the job in grayscale.

" 
                                             + "Are you sure you would like this print job in colour?",
                                             {"dialogTitle" : "Colour print job", 
                                              "dialogDesc"  : "Consider printing in colour to reduce costs"});
   
   if (response == 'No') {
     actions.job.convertToGrayscale();
   } else if (response == 'TIMEOUT') {
     actions.job.cancel();
   } else {
     return;
   }
 }
 
 
 
 
}​

Posted
Shouldn't "dialogDesc" : "Consider printing in colour to reduce costs"}); be "dialogDesc" : "Consider printing in monochrome to reduce costs"});?
  • 3 years later...
Posted

This was really useful, should be a default in papercut. I modified the Script to say Black & White as people understand better than grayscale or monochrome. The Script is

 

/*

* Color print jobs require user confirmation

*

* Color printing is expensive so users should be encouraged to print

* in grayscale whenever they print in color. No confirmation is required

* for grayscale jobs.

*/

function printJobHook(inputs, actions) {

/*

* This print hook will need access to all job details

* so return if full job analysis is not yet complete.

* The only job details that are available before analysis

* are metadata such as username, printer name, and date.

*

* See reference documentation for full explanation.

*/

if (!inputs.job.isAnalysisComplete) {

// No job details yet so return.

return;

}

 

// Test if the job is color (contains at least 1 color page)

if (inputs.job.isColor) {

// Add your action code here

var response = actions.client.promptYesNo("This print job is Colour"

+ " and costs " + inputs.utils.formatCost(inputs.job.cost)

+ ". You can save money by printing the job in Black & White.

 

"

+ "Press Yes to continue this print job in Colour.

Press No to Print in Black & White",

{"dialogTitle" : "Colour Print Job Detected",

"dialogDesc" : "Consider printing in Black & White to reduce costs"});

 

if (response == 'NO') {

actions.job.convertToGrayscale();

} else if (response == 'TIMEOUT') {

actions.job.cancel();

} else {

return;

}

}

 

 

 

 

}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...