PDF Automation Station

PDF Automation Station

Buttons That Add And Delete PDF Pages

Sometimes there's not enough room on a PDF form for the information that needs to be captured.

David Dagley's avatar
David Dagley
Dec 23, 2023
∙ Paid
Share

In fact, the form might require multiple copies of the same page, depending on the situation.  The user might only need one page, or two, or any number of copies of the same page.  To avoid creating a PDF form that displays multiple pages that might never be used, because they are copies of the same page, buttons for adding and deleting pages can be placed on the form. Additional pages are only displayed when needed.  Doing this properly presents some challenges.

Challenges

1)    As I wrote about in my post Check Boxes That Show And Hide PDF Pages, you can't show and hide template pages with Adobe Reader so the pages must be spawned to accommodate end users without access to Acrobat Pro.  Reader can only delete pages that were spawned in the current session – another reason spawning is the solution.

2)    When spawning template pages, there is an option of whether or not to rename the fields.  If the purpose of the form is to capture additional information with each spawned page, the fields must be renamed, because multiple fields with the same name can only have one value.  If you change the value in one field it will automatically change in all fields with the same name.

3)    In this example the template page contains math calculations that need to work separately on every page created during spawning.  Because the fields will be renamed, the calculations must anticipate the renamed field names and adjust for them, so that they work on every spawned page, no matter how many pages are spawned.  In my article Anticipating Field Names In Custom Calculation Scripts, I described in detail how to extract the number suffix from an anticipated field name when the Right-Click > Place Multiple Fields function is used, then add the suffix back into the field names so the calculation works on each additional field without having to modify the script.  For template pages spawned with renamed fields, a prefix is added to the field names.  I will demonstrate how to anticipate the new field names, extract the prefix from the field names, and add it back into the field names in the calculation script so it works on every spawned page, without having to modify the script.

4)    As pages are added and deleted using the buttons, the page numbers need to adjust so they are always correct.  Since the page numbers are field values, they must be prevented from clearing their values if the form contains a reset button.

5)    This project will start as a one-page document with an Add Page button only (no Delete Page button).  The Add Page button will only be available on the last page that is spawned so that additional pages are added in order.  The last spawned page will also contain a Delete Page button to force spawned pages to be deleted in the reverse order of which they were created.  Once the Add Page button from the original page is activated it needs to be hidden so it can't be used again, unless all spawned pages are deleted, and only the original page is present again.  When spawned pages are deleted, the Add Page button needs to appear on the last spawned page only (or the original page if that is the only one remaining).

The Add and Delete Page buttons would normally appear at the bottom of the pages, but I placed them in the top part of the page under the calculation so that scrolling is unnecessary when testing and demonstrating this project.

Video of Completed Project

Get the course above, and a suite of automation tools for FREE with a Professional subscription.

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 David Dagley
Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture