Delete last page at runtime | Community
Skip to main content
Level 2
July 4, 2018
Solved

Delete last page at runtime

  • July 4, 2018
  • 19 replies
  • 9484 views

We've got an invoice adobe form in SAP where the last page should always be printed on a different kind of paper.

That requires us to use a different intput and output tray for the last page.

Out current workaround idea:

Print the document twice: First time without the last page, second time only the last page. This way we have 2 separate print jobs and can control the intput/output tray as we may. But we can't manage to always delete the last page.

The pages are filled using repeating subforms. We don't know how many times the subforms are repeated at design time, and how large they'll be.

Any ideas on how to solve this?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by _Bruce_Robertson

Hi,

You could move the script to the layout:ready event.  You will need to force the relayout to get the presence update to take effect.  The problem then is to stop this script from firing again as you will probably end up with all the pages hidden eventually as the relayout will trigger the layout:ready event.

Try this code in the layout:ready event of Formular1.

if (!PagesHidden.value) {
      var pageCount = xfa.layout.pageCount();
      var lastVisible = null;
      for (var i = content._repeating_subform.count - 1; i >=0; i--) {
            if (xfa.layout.page(content.repeating_subform.all.item(i)) == pageCount) {
                 content.repeating_subform.all.item(i).presence = "hidden";
            } else {
                if (lastVisible == null) {
                      lastVisible = content.repeating_subform.all.item(i);
                }
            }
      }
      if (xfa.layout.pageSpan(lastVisible) > 1) {
          lastVisible.presence = "hidden";
      }
      PagesHidden.value = "1";
      xfa.layout.relayout();
}

PagesHidden is a form variable with an initial value of zero.  This gets set to "1" so the script only executes once.

19 replies

_Bruce_Robertson
Level 10
July 5, 2018

So what software is producing the PDF, one of the server products like LiveCycle Output?  How will the script know to delete the last page or all but the last page?

Level 2
July 7, 2018

It's called Adobe Document Services (ADS), a cross-product of Adobe and SAP. I don't know how the script can delete the last page or all but, and that's exactly what I'm trying to find out. Any ideas on that?

_Bruce_Robertson
_Bruce_RobertsonAccepted solution
Level 10
July 9, 2018

Hi,

You could move the script to the layout:ready event.  You will need to force the relayout to get the presence update to take effect.  The problem then is to stop this script from firing again as you will probably end up with all the pages hidden eventually as the relayout will trigger the layout:ready event.

Try this code in the layout:ready event of Formular1.

if (!PagesHidden.value) {
      var pageCount = xfa.layout.pageCount();
      var lastVisible = null;
      for (var i = content._repeating_subform.count - 1; i >=0; i--) {
            if (xfa.layout.page(content.repeating_subform.all.item(i)) == pageCount) {
                 content.repeating_subform.all.item(i).presence = "hidden";
            } else {
                if (lastVisible == null) {
                      lastVisible = content.repeating_subform.all.item(i);
                }
            }
      }
      if (xfa.layout.pageSpan(lastVisible) > 1) {
          lastVisible.presence = "hidden";
      }
      PagesHidden.value = "1";
      xfa.layout.relayout();
}

PagesHidden is a form variable with an initial value of zero.  This gets set to "1" so the script only executes once.

Level 2
July 10, 2018

Hi Brue,

thanks again for the extensive answer and explanation.

Unfortunately the script does only help when deleting the last page.

We have masterpages FIRST, NEXT and LAST.

If we remove every element except the ones on the last page, the content would be printed on masterpage FIRST instead of LAST.

Is there maybe a way to switch masterpages at runtime?

It would be way easier if the deletePages(n-1, 1) command would still be available .

Is there a similar command available? Can we maybe use the pageSet to remove pages?

_Bruce_Robertson
Level 10
July 10, 2018

Hi,

I new the script was only going to help deleting the last page, that is why I asked how it was going to know to delete the last or all but the last two responses ago.

The only way I know of switching master pages at runtime is to duplicate the form, one for each master page and then only add the interactive pages for the master page you want.

Even if the deletePages() method was available how are you going to tell it to delete the last or all but the last.

Level 2
July 10, 2018

Hi Brue,

ok, I understand now what you meant.

Well, if deletePages() would work, the script could be as follows:

this.deletePages(xfa.layout.pageCount(), 1);

xfa.layout.relayout();

(Pseudocode)

Having each page duplicated sounds costy, but I guess it's a costy requirement anyways.

Do you mean duplicating the whole XDP file, or the Form WITHIN the file?

_Bruce_Robertson
Level 10
July 11, 2018

Hi,

There's an example in this blog of choosing different page sizes at run time (which means choosing different master pages).  It uses a technique to define the form once and placing it under the reference element in the form structure.

Maybe they will help

Level 2
July 16, 2018

Hi Brue,

I have bin looking for the blog post you are talking about, but I can't find it at all.

Where can I find this technique?

Best regards

Joschka

Level 2
July 16, 2018

Ok, I was able to combine your solutions to a working prototype.

I am using a dummy-subform in "repeating_subform", which has the target "last_page". This subform is hidden by default.

With your script from above I now determine which subform-instances are on the last page, and set the dummy-subform to "visible" for all corresponding instances. Then I use relayout() to apply the changes.

This way I have the last page on a different master page and can now use a different paper tray.

Thanks again for all your help.