Copy link to clipboard
Copied
I have a trusted function that I use to allow silent printing of a form when a button is clicked. Works great.
However, would like to specify the printer that is used. Would like to do this using trusted function script as colleague and I using same form from shared location have different printers. Of note, using default printer is no good as that changes depending on what was last printed.
Currently my working code is:
sPrint = app.trustedFunction(function(bUI, bSilent)
{
app.beginPriv();
this.print(false, false);
app.endPriv();
});
Somehow I think I need to add/incorporate this:
var pp = this.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
pp.printerName = "Brother printer";
this.print(pp);
Can anyone please advise? Thank you.
The question is how flexible you want it to be. Do you want to hard-code the printer name into the trusted function, or do you want to pass it as a parameter, so it's easier to change from file to file? If you want it all to be hard-coded, then you can use this code as the folder-level script:
...sPrint = app.trustedFunction(function(doc) {
app.beginPriv();
var pp = doc.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
pp.printerName = "Brother printer";
Copy link to clipboard
Copied
Change your trusted function to this:
sPrint = app.trustedFunction(function(doc, pp) {
app.beginPriv();
doc.print(pp);
app.endPriv();
});
And then call it like so:
sPrint(this, pp);
Copy link to clipboard
Copied
Thanks for the reply but where do I put the second set of code that details the printer name and silent printing? It needs to be in the trusted function javascript file as that file will be different on my computer an my colleague's - her js file will specify a different printer.
Copy link to clipboard
Copied
Would this work:
sPrint = app.trustedFunction(function(doc, pp) {
app.beginPriv();
var pp = this.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
pp.printerName = "Brother printer";
doc.print(pp);
app.endPriv();
});
Copy link to clipboard
Copied
You can pass the printer name as a parameter to the trusted function
Copy link to clipboard
Copied
Thanks for your help. However, as you can see from the code above (which I just checked and doesn't work) my grasp of javascript is not great. Can you share the code for what you suggest above, please?
Copy link to clipboard
Copied
The question is how flexible you want it to be. Do you want to hard-code the printer name into the trusted function, or do you want to pass it as a parameter, so it's easier to change from file to file? If you want it all to be hard-coded, then you can use this code as the folder-level script:
sPrint = app.trustedFunction(function(doc) {
app.beginPriv();
var pp = doc.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
pp.printerName = "Brother printer";
doc.print(pp);
app.endPriv();
});
And then you call it like this:
sPrint(this);
Copy link to clipboard
Copied
Thank you so much for your help. That's exactly what I was looking for - works perfectly!
Kind regards,
Richard
Find more inspiration, events, and resources on the new Adobe Community
Explore Now