Print button select page to print and how many copies to print in javascript ?

Hi,
I have Print button on page with javascript I want to print either page 1 to 5 without a dialog box and just be asked how many copies of the selected page to print with a dialog box.

I found this code to ask how many copies, but cant work out how to add which page to print.
something like
this.print({ bUI: false, bSilent: true, bShrinkToFit: true, nStart: 2, nEnd: 2, });

//and add this


var n = app.response("Number of copies: ");

var pp = this.getPrintParams();
if (n > 0) {
pp.interactive = pp.constants.interactionLevel.silent;
pp.NumCopies = eval(n);
this.print(pp);}

Put together it does not work.

All and any help would be appreciated.


Thanks
Stephen


Stephen Kyle


5 Answers

Voted Best Answer

Can you install (or ask the users to install) a script on the local machine of each person who is going to use this file? If not, then you can't do it.

.


Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


By Gilad D (try67)   

To set the page range to print you need to edit the values of the nStart and nEnd parameters, which are 0-based page numbers. So to print pages 1 to 5 you would specify:

nStart: 0, nEnd: 4

However, printing silently is only possible if a script is used from a trusted context, which usually means that is installed on the local machine of the user, not just embedded in the PDF file.

.


Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


Gilad D (try67)   

Are you saying I cant use the second part then?

Do you have any idea how I could do this then.

Print button

script says print page 2 of 2

and then asks user how many copies of page 2 they want to print

another button

sript says print page 3 of 3

and then asks how many copies of page 3 they want to print

etc


Stephen Kyle   

Nope cant do it.

Well thanks for your input.


Stephen Kyle   

Strangely the following snippet is printing silently from a button field:

var pp = this.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
pp.printerName = "Adobe PDF";
this.print(pp);

the same is true if I use silent in place of automatic

Should I worry about a system security shortfall (the document doesn't seem to be trusted - I mean it is not listed under Edit | Preferences... | Enhanced Protection | Trusted Places)?

Indeed, it should not print silently according to the official documentation: http://livedocs.adobe.com/acrobat_sdk/11/Acrobat11_HTMLHelp/JS_API_AcroJS.89.1001.html

If you can replicate the same, you may also select how many pages to print, either
1. through another print param if it exists;
or
2. looping the above snippet as much as required;

Hope it helps.


Ricardo Falegnami   


Please specify a reason: