Restrict Printing to Selected Websites

This time we want to look at a script that allows you to restrict printing to certain websites.

The script is using the SiteKiosk Object Model and runs as an external script. It can be used with the Chrome engine as well as the Internet Explorer engine.

To add the external script, open the SiteKiosk Configuration, go to Start Page & Browser and click on the Advanced button. In the dialog that will open, you can add an external script file. The following screenshot shows this for the Chrome engine of SiteKiosk.

 

To make the script work, you also need to enable printer monitoring on the Print page of the SiteKiosk Configuration.

 

Let's move onto the script now. Save the code below as a .js file in the HTML subfolder of your SiteKiosk installation, e.g. C:\Program Files (x86)\SiteKiosk\Html\restrictprinting.js.

//CONFIGURATION START

var gk_PrintingAllowed = new Array();

//Add URLs you want to allow printing for
gk_PrintingAllowed[0] = "https://www.provisio.com";
//Add additional URLs here
//gk_PrintingAllowed[1] = "https://www.google.com";
//gk_PrintingAllowed[2] = "http://www.bing.com";

//CONFIGURATION END

var gk_job;
SiteKiosk.Printer.OnNewJob = OnNewJob;

function OnNewJob(printer, job){
	gk_job = job;
	evtid = SiteKiosk.Scheduler.AddDelayedEvent(500, PrintOrNot);
}

function PrintOrNot(){
	var stopprinting = true;
	
	for(var i=0;i<gk_PrintingAllowed.length;i++){
		if(gk_job.Document.indexOf(gk_PrintingAllowed[i]) != -1){
			stopprinting = false;
		}
		
		if(!stopprinting)
			break;
	}

	if(stopprinting){
		SiteKiosk.Logfile.Notification("Deleting print job because URL is not allowed for printing."); //Debug
		gk_job.Delete();
	}
}

The script uses the array gk_PrintingAllowed for all the URLs you want to allow printing from. Add additional URLs by counting up the numbers, gk_PrintingAllowed[1] = "https://www.google.com"; then gk_PrintingAllowed[2] = "http://www.bing.com"; and so on.

The print jobs are monitored using the OnNewJob event. When this is fired, we receive a JobInfo object for the specific job. We then give the job a little time to be processed by using the AddDeleyedEvent method, before calling the PrintOrNot function, where we check if the URL of the print job is in the array of allowed URLs using a simple string comparison.

If the URL is not allowed, the script writes a short notification to the SiteKiosk logs using the Notification method and then uses the Delete method of the JobInfo object.

In case you want to inform the user about the deleted print job, you might use the CreateHTMLDialog method to display a dialog.