Skip to main content
Participating Frequently
November 25, 2016
Answered

How to specify specific printer to print silently using trusted function?

  • November 25, 2016
  • 1 reply
  • 2408 views

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.

This topic has been closed for replies.
Correct answer try67

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(); 

});


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);

1 reply

try67
Community Expert
Community Expert
November 25, 2016

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);

Participating Frequently
November 25, 2016

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.

Participating Frequently
November 25, 2016

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(); 

});