Other PDF Issues

How to Display the Third-to-Last Page with an Acrobat Button Script

Camila MilosovichCamila Milosovich Nov 10, 2026 868 views

Question details

The user needs a way to make a PDF button dynamically jump to the third-to-last page without using a fixed page view link.

How to Navigate to the Third-to-Last Page Using an Acrobat Button Script
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating an interactive PDF button that retains correct relative page navigation even after new pages are inserted or existing ones are deleted.
Observed behavior
The standard 'Go to a Page View' action statically links to a specific page number, which breaks when the document length changes.
Before you start

Ensure you are using a PDF editor that supports JavaScript actions, such as Adobe Acrobat Pro, and verify your document has at least three pages to prevent script errors.

Solution 1Recommended

Add a JavaScript Action to the PDF Button

Use a simple JavaScript calculation in the button's properties to dynamically determine the destination page based on the current total page count.

By utilizing Acrobat's built-in JavaScript API, you can calculate the exact destination page on the fly. Since the script checks the total document length each time the button is clicked, it will remain accurate regardless of how many pages you add or remove.

1
Enter form editing mode

Open your PDF document in Adobe Acrobat, navigate to the 'Tools' menu, and select 'Prepare Form' to enable interactive element editing.

2
Access button properties

Right-click the specific button you want to configure and select 'Properties' from the context menu.

3
Assign the JavaScript action

Go to the 'Actions' tab. In the 'Select Action' dropdown menu, choose 'Run a JavaScript', and then click the 'Add' button.

4
Input the script

In the JavaScript Editor window, type the following exact code: this.pageNum = this.numPages - 3; then click 'OK' to save.

5
Test the navigation

Close the form editing mode and click your button to verify it successfully transports your view to the third-to-last page.

Add a JavaScript Action to the PDF Button
Zero-Based Indexing Explanation: Acrobat JavaScript page numbering starts at 0 (the first page is page 0). The property this.numPages returns the actual total count. Subtracting 3 accurately lands on the third-to-last page due to this offset.
Free Microsoft Office alternative

Manage and Edit PDFs Effortlessly with WPS Office

While advanced JavaScript button scripting is natively handled in specialized Acrobat tools, WPS Office provides a powerful, lightweight, and free alternative for managing, reading, and editing PDF files alongside Word, Excel, and PowerPoint documents.

Fully compatible with standard PDF formats and Microsoft Office files.Easily view, edit, annotate, and manage PDF pages in an intuitive interface.Lightweight software suite that runs smoothly on Windows, Mac, and Linux.Convert seamlessly between PDFs and editable Office formats.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the script subtract 3 instead of 2 to get the third-to-last page?

In Acrobat's JavaScript API, page numbers are zero-based, meaning page 1 is index 0. The numPages property is a standard 1-based count. To access the final page, you would use numPages - 1. Consequently, subtracting 3 lands you exactly on the third-to-last page.

Will this button script keep working if I merge another PDF into the current document?

Yes. Because the script dynamically references the this.numPages property every time the button is clicked, it recalculates the total page count and will reliably jump to the new third-to-last page after the merge.

Can I apply this same JavaScript to a bookmark instead of a form button?

Absolutely. You can right-click a bookmark, choose Properties, navigate to the Actions tab, and select 'Run a JavaScript'. Inputting the exact same code will make the bookmark dynamically navigate just like the button.

What happens if my PDF document has fewer than three pages?

If the document is shorter than three pages, the calculation will result in a negative number. This typically causes the PDF viewer to ignore the command and stay on the current page, or it may trigger a silent background error. It is best used on longer documents.