Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Print button requires a second click to print after changing presence of another page to visible

Avatar

Level 2

I'm having trouble getting a print button to execute two separate lines of code.  I need it to make the second page of a form printable and then print, it makes page 2 visible but then when the print dialog box comes up the only page that is there is page 1.  Can I get them to execute one after the other with one click???  I've played around with the prePrint and no luck there either.  Page2 is set to hidden again on the postPrint which works fine.

I've created a very simple version of this problem, 2 pages, page 2 is set to hidden on initialize.  On page 1 is a button with only this code on the click event:

event:click

Pg2.presence = "visible";

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

And it still only displays page 1 in the print dialog even though on the preview behind that pop-up I can see the document is 2 pages long now!!  What am I missing here?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 8

Try this:

Pg2.presence="visible";

var MyDoc = event.target;

var pp = MyDoc.getPrintParams();

var fv = pp.constants.flagValues;

pp.flags |= (fv.setPageSize);

pp.pageHandling = pp.constants.handling.none;

MyDoc.print(pp);

Let me know if all your printer settings still work with that (particularly printing annotations, as you had it set to false and it's default to true).

Kyle

View solution in original post

7 Replies

Avatar

Level 8

The layout model didn't have a chance to update right after you set the presence to "visible". Therefore the numPages property didn't update and only sees there being the one page.

You need to force a 'refresh' with xfa.layout.relayout() right after you change the presence property of Pg2. Then instead of using a host property (numPages), use a layout method. In other words replace xfa.host.numPages with xfa.layout.pageCount().

Your end result will be:

Pg2.presence="visible";

xfa.layout.relayout();

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

Kyle

Avatar

Level 2

Hi there, I just tried adding the relayout line and no luck, it still only shows the one page in the print dialog pop-up.... (also only one page when I printed to pdf).

When I add the line with the pageCount I don't get the print dialog box at all....:(

Avatar

Level 8

Whoa. My bad. I could have swore I got it working. I'll keep trying...

Kyle

Avatar

Correct answer by
Level 8

Try this:

Pg2.presence="visible";

var MyDoc = event.target;

var pp = MyDoc.getPrintParams();

var fv = pp.constants.flagValues;

pp.flags |= (fv.setPageSize);

pp.pageHandling = pp.constants.handling.none;

MyDoc.print(pp);

Let me know if all your printer settings still work with that (particularly printing annotations, as you had it set to false and it's default to true).

Kyle

Avatar

Level 2

Wow, I would not have come up with that on my own!!  Thanks!  This works perfectly on my dumbed down version, I'm just not sure how easily I will be able to get it working on my real project where I need to specify which pages to print at different times.  Here is the print line that we need to run (it's wrapped in an if statment and the page numbers to print change depending on some radio buttons).

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

Sarah

Avatar

Level 8

pp.firstPage=2;

pp.lastPage=3;

Don't forget to mark as Correct!

Thanks.

Kyle