Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Printing only last two pages.

Avatar

Former Community Member

The Accurate Info button on my form will make two last hidden pages on the form visible and set focus to the first field on the first Info page. The whole form has dynamic subforms and they can grow so I do not know the exact number of the pages at the end. I want to have a print button on these two Info pages that will print only them, not the entire form. Can someone please provide some help on this one.

Thank you,

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If you drag a standard print button onto the page, you will see that it has eight parameters:

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

The second parameter specifies the start page "0", as the page numbers use a zero numbering system. The first page of your form is "0".

The third parameter specifies the last page to be printed. This is a basic calculation where xfa.host.numPages counts the total number of pages AND -1 brings this into the zero numbering system.

All you need to do is add a line to work out the page number that the print button is on (eg second plast page) and then use this information in parameters 2 and 3.

var vPage = xfa.layout.page(this);

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

The vPage will get the page number, counting from 1. The print parameters then use this information to set the start page and end page. No matter how many pages are ahead of the last two pages, this script will always print the page with the print button and the next page.

Hope that helps,

Niall

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

Hi,

If you drag a standard print button onto the page, you will see that it has eight parameters:

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

The second parameter specifies the start page "0", as the page numbers use a zero numbering system. The first page of your form is "0".

The third parameter specifies the last page to be printed. This is a basic calculation where xfa.host.numPages counts the total number of pages AND -1 brings this into the zero numbering system.

All you need to do is add a line to work out the page number that the print button is on (eg second plast page) and then use this information in parameters 2 and 3.

var vPage = xfa.layout.page(this);

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

The vPage will get the page number, counting from 1. The print parameters then use this information to set the start page and end page. No matter how many pages are ahead of the last two pages, this script will always print the page with the print button and the next page.

Hope that helps,

Niall

Avatar

Former Community Member

Thank you so much. You've explained it so well.

Avatar

Level 2

Helped me too!  many thanks Niall.

Avatar

Level 6

Hi Niall,

How can this be modified to print just the last page?

I have a situation where I need to place a print button on a repeating subform which is the size of an entire page. If I place the print button on a master page it will automatically show up on every new instance.  Hoe can I program the button to just print the last page which will always be the last instance?

Thanks in advance.

Shaun

Avatar

Level 8

use xfa.host.print with the xfa.host.numPages to print just the last page

Avatar

Level 6

TundraSteve - thanks for the reply.

I'm not sure I follow (pardon my lack of knowledge)

Do you mean: xfa.host.print(1, "0", (xfa.host.numPages).toString(), 0, 0, 0, 0, 0); //removed -1

or

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

Neither seemed to work.

Thanks