Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Nov 25, 2016 Nov 25, 2016

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.

TOPICS
Acrobat SDK and JavaScript , Windows
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 25, 2016 Nov 25, 2016

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

...
Translate
Community Expert ,
Nov 25, 2016 Nov 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2016 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2016 Nov 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(); 

});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 25, 2016 Nov 25, 2016

You can pass the printer name as a parameter to the trusted function

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2016 Nov 25, 2016

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2016 Nov 25, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2016 Nov 25, 2016
LATEST

Thank you so much for your help. That's exactly what I was looking for - works perfectly!

Kind regards,

Richard

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines