Expand my Community achievements bar.

SOLVED

Javascript: Passing values to Print Dialog

Avatar

Level 2

hi,

I have a PDF page containg 8 pages. On first page there is a Print button and some select boxes (Page1, Page2, .. Page8)

I want to open Print Dialog with page numbers already set from the select boxes.

Example: If i have checked Page1, Page 4 check boxes then Print Dialog should show the values in  Print Rang > Pages [1,4]

how can i do this using javascript?

Please help me out

thanks

Faraz

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Faraz,

That's the problem, you cannot specify a print range with gaps.

xfa.host.print(1, "0", "7", 0, 1, 0, 0, 0);

The second parameter specifies the start page (based on a zero numbering system). Therefore "0" will print from page 1 of the form.

The third parameter specifies the last page to be printed. Therefore "7" will print page 8 of the form.

Here is a sample of the only workaround I can think of. Basically the button opens the print set up dialogue (not the standard print window). This allows the user to select the correct printer and settings. Then the script looks at each page in turn and prints is as a standalone print job. If you look at the print command you will see that the first parameter is set to "0", this is to print the page without displaying the print dialogue. The fourth parameter is now set to "1" to prevent the user cancelling the print job. If you look at the help file you will get a full description of the print command and all eight parameters.

xfa.host.print(0, "0", "0", 1, 1, 0, 0, 0);

Hope that helps,

Niall

View solution in original post

10 Replies

Avatar

Level 10

Hi,

In LC Designer you do not (as far as I know) have as much access to print properties than you do in Acrobat (which uses printParam).

The XFA print command had eight parameters. The second and third parameters specify the start page and finish page for printing, based on a zero numbering system.

I think that you will be able to specify a start page and an end page using javascript (eg 3-5). But it would be more complicated to specify a range with gaps (eg 3-4,6,8).

The standard XFA command in a print button is:

xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);

The third parameter is looking at the total number of pages. You can change this to refer to values of objects in your form that relate to the start and finish pages to be printed.

xfa.host.print(1, (NumericField1.rawValue -1).toString(), (NumericField2.rawValue -1).toString(), 0, 1, 0, 0, 0);

Or you could set up an if statement to look at a number of objects in the form and determine the start and finish pages.

I think this is as far as you can take it. The only other alternative is calling the print command a number of times to deal with gaps in the printing range, but this may become tiresome for the user.

Good luck,

Niall

Avatar

Level 2

Can u please tell me the exact command i need to print pages 3-4,6,8

I tried like this but its not working

xfa.host.print(1, "3,4,6,8", "4", 0, 1, 0, 0, 0);

thanks

Faraz

Avatar

Correct answer by
Level 10

Hi Faraz,

That's the problem, you cannot specify a print range with gaps.

xfa.host.print(1, "0", "7", 0, 1, 0, 0, 0);

The second parameter specifies the start page (based on a zero numbering system). Therefore "0" will print from page 1 of the form.

The third parameter specifies the last page to be printed. Therefore "7" will print page 8 of the form.

Here is a sample of the only workaround I can think of. Basically the button opens the print set up dialogue (not the standard print window). This allows the user to select the correct printer and settings. Then the script looks at each page in turn and prints is as a standalone print job. If you look at the print command you will see that the first parameter is set to "0", this is to print the page without displaying the print dialogue. The fourth parameter is now set to "1" to prevent the user cancelling the print job. If you look at the help file you will get a full description of the print command and all eight parameters.

xfa.host.print(0, "0", "0", 1, 1, 0, 0, 0);

Hope that helps,

Niall

Avatar

Level 10

A workaround I've seen mentioned before is to hide the pages you don't want before printing and make them visible again after printing.

Avatar

Level 10

Duh... Jono is right and his solution would also work if the user printed from the Acrobat print menu item.

If you delete the button in the example and have the following in the prePrint event of the checkbox on each page (just change the page reference:

if (this.rawValue == 0) // not checked

{

     page1.presence = "hidden"; // the SOM reference will have to relate to each page reference

}

else

{

     page1.presence = "visible";

}

Then in the postPrint event you would have just a single line to make sure that the page is made visible again:

page1.presence = "visible";

Sorry about the mis-direction. Jono's solution is much simpler to implement. Just note you can't hide all pages, so that if none of the pages are ticked, then a single blank page will print.

Good luck,

Niall

Avatar

Former Community Member

2009-11-15 Printing different pages.pdf

This pdf doesn't work. I select the pages I want to print and click the print button and nothing happens.

Avatar

Former Community Member

I tried your suggestion, but it always says "failed to print, no pages selected." Even when I have the box checked.

Avatar

Former Community Member

I've tried hiding the pages, but I still get 3 blank pages printing eventhough I've selected other pages to print.

Avatar

Level 10

Hi,

Sorry for the delay.

I have had a look at the form and for some reason the script was missing from the checkbox on all but the first page. I have corrected this and hopefull the updated example will give you a direction:

https://acrobat.com/#d=BiyCjZJoeK9rmZDcZLXIwA.

Hope that helps,

Niall

Avatar

Former Community Member

Document wasn't coming up. We settled on individual print dialog boxes for each set of pages/documents the want to print.