Jump to content

Recommended Posts

Posted

Hi Everyone,

 

I have an issue that I really hope you can help with.

 

I am looking for a way to deny print jobs that contain in them "%20".

 

Essentially the issue I'm having is that we use Google chrome and for some reason its print preview option doesn't talk very well to our printers and wont print in B&W for example. I am unable to find a way to disable it for all users so I'm looking to go this route instead. I've noticed that files printed through the print preview are always named "document%20name%20.pdf" so I want to be able to deny those prints ideally with a message to display advising them to download the document instead and print normally or something of that nature.

 

The only catch is this - I don't know java script at all.

 

Does anyone have a script that would be similar to my needs and fairly simple for me to understand so I could edit it or would some kind soul consider writing something for me?

 

Kind Regards

 

Chris

Posted

printJobHook(inputs, actions) - use this hook.

 

inputs.job.documentName - this gets the document name. Then do something like.

 

var n = inputs.job.documentName.indexOf("%20");

 

if n > 0 then is detected it... you could then rename or replace the text of the document.

 

 

  • Thanks 1
Posted (edited)
You can deny job names in the filters and restrictions, there is an option to specify it there.

 

Hi Matthew,

 

Thanks, I did see this option but as far as I can see its not a name contains filter. It looks like that is for explicitly blocking a named file like "mydocument.doc" not like "anything that contains the word document and is a PDF gets blocked". That is unless there is a particular syntax in that box that I'm supposed to put in that I'm missing?

 

Kind Regards

 

Chris

Edited by Finchy911
Posted
printJobHook(inputs, actions) - use this hook.

 

inputs.job.documentName - this gets the document name. Then do something like.

 

var n = inputs.job.documentName.indexOf("%20");

 

if n > 0 then is detected it... you could then rename or replace the text of the document.

 

 

 

Hi Broomop,

 

This is great! So this code analyses the job name and it will give me either a 1 or 0 result based on that test if I understand that correctly?

 

Assuming that is correct I'd put some code stolen from elsewhere to deny the job and do message boxes and what not to get it to do what I want?

 

Kind Regards

 

Chris

Posted
Hi Broomop,

 

This is great! So this code analyses the job name and it will give me either a 1 or 0 result based on that test if I understand that correctly?

 

Assuming that is correct I'd put some code stolen from elsewhere to deny the job and do message boxes and what not to get it to do what I want?

 

Kind Regards

 

Chris

 

Yes indexof just responds back with a value where its located @ in the text. If i remember correctly. for example hello%20 would be found at number 6. If it finds nothing its -1. If you look up the documentation on JS and the indexof function it will help you out. Yes there are snippets you can use. I would of given you the full code however at the time i was busy. If you want the full code of how it should work just reply back.

 

Thanks.

  • Thanks 1
Posted
Yes indexof just responds back with a value where its located @ in the text. If i remember correctly. for example hello%20 would be found at number 6. If it finds nothing its -1. If you look up the documentation on JS and the indexof function it will help you out. Yes there are snippets you can use. I would of given you the full code however at the time i was busy. If you want the full code of how it should work just reply back.

 

Thanks.

 

Hi Broomop,

 

I had a very good go at trying to do it myself which ended up looking like this:

--------------------------------------------------------------------

"//

// Customize your print process with Print Scripting. You don't have to be a

// programmer to use Print Scripting. Use one of the many pre-written recipes

// already written for you, or write your own in JavaScript using snippets and

// reference documentation.

//

function printJobHook(inputs, actions) {

inputs.job.documentName - this gets the document name. Then do something like.

 

var n = inputs.job.documentName.indexOf("%20");

 

if n > 0 then

 

 

{

actions.job.cancel();

actions.log.debug('Job from user "' + inputs.user.username + '" was canceled.');

}

 

}

 

---------------------------------------------------------------

 

Unfortunately as may be obvious I'm garbage at scripting/understanding javascript and it just says I have a syntax error.

 

What I'm going for as you know is to analyse the job name and if it contains a certain string then to deny the job, then send a message back to the user that I can add my own text into to explain why their job was denied.

 

It shames me to ask but could you please write something like this for me as I cant seem to get a grasp on how exactly this is done.

 

If you could do this for me I'd be forever in your debt sir! :rolleyes:

Posted (edited)

you need brackets "if( n > 0 )"

 

try that. where is the syntax error at... maybe it doesnt even like indexof...

 

 

function printJobHook(inputs, actions) {

var n = inputs.job.documentName.indexOf("%20");

if (n > 0)

{

actions.job.cancel();

actions.log.debug('Job from user "' + inputs.user.username + '" was canceled.');

}

 

}

Edited by broomop
  • Thanks 1
Posted
you need brackets "if( n > 0 )"

 

try that. where is the syntax error at... maybe it doesnt even like indexof...

 

 

function printJobHook(inputs, actions) {

var n = inputs.job.documentName.indexOf("%20");

if (n > 0)

{

actions.job.cancel();

actions.log.debug('Job from user "' + inputs.user.username + '" was canceled.');

}

 

}

 

 

Hi Broomop,

 

Thanks for your advice my friend, this is what I have now:

//

// Customize your print process with Print Scripting. You don't have to be a

// programmer to use Print Scripting. Use one of the many pre-written recipes

// already written for you, or write your own in JavaScript using snippets and

// reference documentation.

//

function printJobHook(inputs, actions) {

//

// Customize your print process with Print Scripting. You don't have to be a

// programmer to use Print Scripting. Use one of the many pre-written recipes

// already written for you, or write your own in JavaScript using snippets and

// reference documentation.

//

function printJobHook(inputs, actions) {

inputs.job.documentName - this gets the document name. Then do something like.

 

var n = inputs.job.documentName.indexOf("%20");

 

if (n > 0) then

 

 

{

actions.job.cancel();

actions.log.debug('Job from user "' + inputs.user.username + '" was canceled.');

}

 

}

 

}

 

-----------------------------------------------------------------------------------

The error I'm getting is "The Script failed to validate, check the script syntax: missing ; before statment (Printer-script#15"

 

I wish I knew exactly what that meant other than presumably missing a semi colon somewhere, hopefully that makes a bit more sense to you.

Posted
that would be line 15 i think. Tomorrow morning i will have a mess around and give you the answer. I could only see the brackets part that would be an issue. try removing the actions.job bits too for now. See if you can at least get it to run without failure.
  • Thanks 1
Posted

Hi Broomop,

 

Okay I've taken some bits out leaving me with the following:

1 //

2 // Customize your print process with Print Scripting. You don't have to be a

3 // programmer to use Print Scripting. Use one of the many pre-written recipes

4 // already written for you, or write your own in JavaScript using snippets and

5 // reference documentation.

6 //

7 function printJobHook(inputs, actions) {

8 inputs.job.documentName - this gets the document name. Then do something like.

9 var n = inputs.job.documentName.indexOf("%20");

10 if (n > 0) then

11 }

------------------------------------------------------

I put in line numbers this time to help you debug, having deleted some unnecessary blank lines I have the same error but this time on line 8.

 

I really appreciate the effort you're putting into this mate, I hope I pick up some knowledge about java-script from all of this so I can pay it forward in future! :)

Posted

I noticed right away when i typed it out.... it was the double quotes.

 

this is what i quickly wrote and tested and i believe it will work.

 

function printJobHook(inputs, actions) {

 

var n = inputs.job.inputs.job.documentName;

 

 

 

if(n.indexof('%20') != -1)

{

actions.job.cancel();

}

 

}

 

This should work.

  • Thanks 1
  • 2 weeks later...

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...