PaperCut Print Script of the Month #4 – Colour Only Extensions

PaperCut Print Script – Colour only extensions


This month’s PaperCut Print Script keeps it simple and highlights how we can only allow colour printing from certain applications (for example, Excel, Powerpoint, etc.) based on the file extension. In this example all mono printing is permitted, colour is cancelled if not from one of pre-defined whitelisted applications

Now, before you get excited, this will not work for all applications. It depends on how the print job from the application arrives in a print queue if there is no extension being send then a bit of research would need to be done to work out what the applications send instead that can be used to identify it in the queue. With that small disclaimer out of the way it is time to grab a cup of coffee and get started.

This month we start out with an array which will contain the list of extensions we want to allow colour printing for if you missed last months PaperCut Print Script where we first introduced arrays you can catch up here.

Next up is to work out if the job was actually sent in colour all of our code will be in this if block to make sure it only attempts to run the rest of the script for colour jobs, Luckily PaperCut has a handy method we can use to do this

Now it is time to work out how we are going to get the information out of the array. Last month we directly specified the index to use using something like fileExtensions[1] (in this example that would return .ppt) but we actually want to work with each value and be able to easily change what extension we are allowing. For this, we are going to a for loop which at first might look complicated but it will all make sense

So what we are doing is starting out by setting the value of i to 0 and checking that the value of i is less than the number of extensions in the array if it is we will add 1 to the value of i on the next run. Remember how we manually set the index last month well this month we are making the computer do the work to check each value. This means that on the first loop the value of fileExtensions[i] will be .xls, on the second loop i will equal 1 so fileExtensions[i] will be .ppt and it will keep going through them until the value of i matches what we have in the array.

Now we have that out of the way… lets look at how to work out if the document name contains the extension we are looking for we can use inputs.job.documentName and the indexOf method that can be used on Strings, indexOf will tell us the position that the search string appears and will return a -1 if it doesn’t appear at all. So for this example, we only want to proceed if the extension is found in the filename but the position could be anywhere so for our check we will just make sure the result is not -1.

Now that is all done outside of the loop we can send a message to the client to tell them the document is not allowed to be printed in colour and cancel the job

As always the complete PaperCut Print Script is below and if you have your own requirements for a print script and you don’t have the time or in-house experience to make it you can find out how we can help you by sending an email to our sales team at

PaperCut Print Script
Latest News from Jonathan Bennetts

PaperCut and Access Management

Access Management and Identity as a Service (IDaaS) solutions for PaperCut...

Written by: Jonathan Bennetts


PaperCut ends client support for 32-bit operating syst...

A long time ago, in a country far far away... PaperCut announced they were...

Written by: Jonathan Bennetts



You guys are a pleasure to do business with your support is fantastic I wish all suppliers behaved like you

Duncan Vass Dell Ltd
Back to Top ↑