[9.1.356] JavaScript - Print all opened Docs...
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
[9.1.356] JavaScript - Print all opened Docs...
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
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
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
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.
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: JavaScript - Print all opened Docs...
Hello AndyK,
Reading in the JS API documentation below this code: 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
Reading in the JS API documentation below this code:
Code: Select all
pp.interactive = pp.constants.interactionLevel.silent;
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
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: JavaScript - Print all opened Docs...
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:
And this will add a "Print All" command to the File Menu in the Editor, right under the "Print" command that is already there.
This one will honour the intent and can be made to print all opened documents silently.
Kind regards,
Stefan
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"
});
Kind regards,
Stefan
Re: [9.1.356] JavaScript - Print all opened Docs...
Hi Tracker Supp-Stefan,
your code don't work for me
I see the entry in the file menu, but it has no function.
What do I wrong?
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"
});
-
- User
- Posts: 2394
- Joined: Wed Jan 18, 2006 12:10 pm
Re: [9.1.356] JavaScript - Print all opened Docs...
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"
});
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"
});
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: [9.1.356] JavaScript - Print all opened Docs...
Hello Willy Van Nuffel, AndyK,
Apologies - I should have probably posted the whole JS file last time!
Here it is now: 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
Apologies - I should have probably posted the whole JS file last time!
Here it is now: 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
Re: [9.1.356] JavaScript - Print all opened Docs...
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.
and
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
How can I resolve the problem?
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);
}
}
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);
}
}
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
How can I resolve the problem?
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: [9.1.356] JavaScript - Print all opened Docs...
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:
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:
Kind regards,
Stefan
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:
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:
Kind regards,
Stefan
Re: [9.1.356] JavaScript - Print all opened Docs...
Hi Stefan,
now it works great for me. Many, many thanks for that
════
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
now it works great for me. Many, many thanks for that
════
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
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: [9.1.356] JavaScript - Print all opened Docs...
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
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
Re: [9.1.356] JavaScript - Print all opened Docs...
Hi Stefan,
thanks again
and here the sript for German speaking peoples
thanks again
and here the sript for German speaking peoples
- Tracker Supp-Stefan
- Site Admin
- Posts: 17929
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: [9.1.356] JavaScript - Print all opened Docs...
Hello AndyK,
Many thanks for providing the localized version!
Kind regards,
Stefan
Many thanks for providing the localized version!
Kind regards,
Stefan