[9.1.356] JavaScript - Print all opened Docs...

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
User avatar
AndyK
User
Posts: 102
Joined: Sun Jul 27, 2008 8:52 pm

[9.1.356] JavaScript - Print all opened Docs...

Post by AndyK »

Hi,

I use two JavaScript files for printing all opened pdf files

The first one to print all PDF files WITH print dialog and a second one to pass all PDF files without dialog directly to the default printer driver

printAllOpenedDocs!.zip
(31.92 KiB) Downloaded 46 times

Buttons.png
Buttons.png (28.22 KiB) Viewed 1007 times

The problem - Both buttons do the same thing - no different in the function.
How can I resolve the issues?

Or must I use different commands in the JavaScript files?
https://forum.pdf-xchange.com/viewtopic.php?p=150625#p150625

Thanks for help
Last edited by AndyK on Wed Jul 21, 2021 7:29 am, edited 1 time in total.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: JavaScript - Print all opened Docs...

Post by Tracker Supp-Stefan »

Hello AndyK,

Reading in the JS API documentation below this code:

Code: Select all

pp.interactive = pp.constants.interactionLevel.silent;
is this description:
Outside of batch, console, and menu events, the values of bUI and of interactive are ignored
and a print dialog box will always be presented.

As per your earlier topic:
viewtopic.php?f=62&t=36502
The custom JS commands are now treated differently than in the past, so I presume we are now correctly handling the "interactionLevel" as well.
I will check with our devs, if there's an alternative solution that can be implemented with the current builds!

Kind regards,
Stefan
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: JavaScript - Print all opened Docs...

Post by Tracker Supp-Stefan »

Hello Andy,

As a follow up - as per the specification - the "intent" will be ignored for custom buttons, but as a workaround you can also add custom menu items.
Please replace the "app.addToolButton" in your code with this one:

Code: Select all

app.addMenuItem({ 
 cName: "Print All", 
 cParent: "File",
 cExec: "printAllOpenedDocs();",
 cEnable: "event.rc = (event.target != null);",
 nPos: "Print"
});
And this will add a "Print All" command to the File Menu in the Editor, right under the "Print" command that is already there.
add_PrintAll.png
add_PrintAll.png (20.52 KiB) Viewed 962 times
This one will honour the intent and can be made to print all opened documents silently.

Kind regards,
Stefan
User avatar
AndyK
User
Posts: 102
Joined: Sun Jul 27, 2008 8:52 pm

Re: [9.1.356] JavaScript - Print all opened Docs...

Post by AndyK »

Hi Tracker Supp-Stefan,

your code don't work for me 🙁
I see the entry in the file menu, but it has no function.

Code: Select all

app.addMenuItem({ 
 cName: "Alle drucken (ohne Dialog)", 
 cParent: "File",
 cExec: "printAllOpenedDocs();",
 cEnable: "event.rc = (event.target != null);",
 nPos: "Print"
});
What do I wrong?
Willy Van Nuffel
User
Posts: 2347
Joined: Wed Jan 18, 2006 12:10 pm

Re: [9.1.356] JavaScript - Print all opened Docs...

Post by Willy Van Nuffel »

Hi,

It seems like the functional part is missing in your script.
The script should look like this:

function printAllOpenedDocs()
{
var ad = app.activeDocs;
for (var i = 0; i < ad.length; i++)
{
var pp = ad[i].getPrintParams();
// uncomment the next line to print without dialog for each document
// pp.interactive = pp.constants.interactionLevel.silent;
ad[i].print(pp);
}
}

app.addMenuItem({
cName: "Print All",
cParent: "File",
cExec: "printAllOpenedDocs();",
cEnable: "event.rc = (event.target != null);",
nPos: "Print"
});
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: [9.1.356] JavaScript - Print all opened Docs...

Post by Tracker Supp-Stefan »

Hello Willy Van Nuffel, AndyK,

Apologies - I should have probably posted the whole JS file last time!
Here it is now:
printAllOpenedDocs_new.zip
(581 Bytes) Downloaded 33 times
And there is also a check in that code - so the button will not be active (just like the normal print button) unless there are opened files.

Kind regards,
Stefan
User avatar
AndyK
User
Posts: 102
Joined: Sun Jul 27, 2008 8:52 pm

Re: [9.1.356] JavaScript - Print all opened Docs...

Post by AndyK »

Hi Stefan,

I use this both code in two JS files
One for printing with the print dialog and the other for printing without the print dialog.

Code: Select all

app.addMenuItem({ 
 cName: "Alle drucken (ohne Dialog)", 
 cParent: "File",
 cExec: "printAllOpenedDocs();",
 cEnable: "event.rc = (event.target != null);",
 nPos: "Print"
});


function printAllOpenedDocs(){
  var ad = app.activeDocs;
  for (var i = 0; i < ad.length; i++)
  {
    var pp = ad[i].getPrintParams();
    // uncomment the next line to print without dialog for each document
    pp.interactive = pp.constants.interactionLevel.silent;
    ad[i].print(pp);
  }
}
and

Code: Select all

app.addMenuItem({ 
 cName: "Alle drucken (mit Dialog)", 
 cParent: "File",
 cExec: "printAllOpenedDocs();",
 cEnable: "event.rc = (event.target != null);",
 nPos: "Print"
});


function printAllOpenedDocs(){
  var ad = app.activeDocs;
  for (var i = 0; i < ad.length; i++)
  {
    var pp = ad[i].getPrintParams();
    // uncomment the next line to print without dialog for each document
    // pp.interactive = pp.constants.interactionLevel.silent;
    ad[i].print(pp);
  }
}
but unfortunately both scrips do the same.
If I use only one of them - the script work well. But I need the functionality of both scripts.
And this was the question in my first post :wink:

How can I resolve the problem?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: [9.1.356] JavaScript - Print all opened Docs...

Post by Tracker Supp-Stefan »

Hello AndyK,

You are using the same function name twice, so the second one effectively overwrites the first and that's why both your buttons do the same.
Please try the attached file instead:
printAllOpenedDocs_new.zip
(621 Bytes) Downloaded 41 times

Alternatively - you can pass a parameter to your function - and thus call the same one from the two menu items, and alter the logic of the function based on the parameter passed - please see the updated code below:
printAllOpenedDocs_new_singleFunction.zip
(656 Bytes) Downloaded 40 times

Kind regards,
Stefan
User avatar
AndyK
User
Posts: 102
Joined: Sun Jul 27, 2008 8:52 pm

Re: [9.1.356] JavaScript - Print all opened Docs...

Post by AndyK »

Hi Stefan,

now it works great for me. Many, many thanks for that :D

════

I would be really happy if this feature would be integrated directly into PDF-XChange Editor. So such programming laymen like me would not have to deal with such code.

Thank you
Andy
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: [9.1.356] JavaScript - Print all opened Docs...

Post by Tracker Supp-Stefan »

Hello AndyK,

Glad to hear that!
I also updated my above post - please see the second proposition which makes the code a bit cleaner and easier to understand.

Kind regards,
Stefan
User avatar
AndyK
User
Posts: 102
Joined: Sun Jul 27, 2008 8:52 pm

Re: [9.1.356] JavaScript - Print all opened Docs...

Post by AndyK »

Hi Stefan,

thanks again :D

and here the sript for German speaking peoples :wink:


printAllOpenedDocs_(DE).zip
(540 Bytes) Downloaded 65 times
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: [9.1.356] JavaScript - Print all opened Docs...

Post by Tracker Supp-Stefan »

Hello AndyK,

Many thanks for providing the localized version!

Kind regards,
Stefan
Post Reply