Other PDF Issues

How to Count PDF Pages by Size in Acrobat Pro Using JavaScript

Jason MillerJason Miller Nov 2, 2026 869 views

Question details

The user wants to count the number of pages in a PDF document based on their dimensions (e.g., A3, Legal, US Letter, and custom sizes) using Adobe Acrobat Pro.

How to Count PDF Pages by Size in Adobe Acrobat Pro
Product
Adobe Acrobat Pro
Device & OS
not provided
Scenario
Managing documents with multiple mixed page sizes and needing an accurate tally of how many pages belong to each standard or custom dimension.
Observed behavior
Acrobat Pro does not offer a native, one-click feature to tally pages by size, so users must rely on custom JavaScript to read the CropBox dimensions of each page and categorize them.
Before you start

Ensure you have Adobe Acrobat Pro installed, as standard Acrobat Reader does not support creating custom JavaScript commands or actions.

Solution 1Recommended

Create an Acrobat Custom Command using JavaScript

Write and execute a custom JavaScript command that iterates through every page, retrieves its dimensions, and tallies the standard page sizes.

Acrobat JavaScript measures page boxes in points (72 points = 1 inch). Because some PDF generators round dimensions slightly, it is best to include a small tolerance ('wiggle room') when comparing the page width and height to standard size points.

1
Access the Action Wizard

Open Adobe Acrobat Pro, go to the 'Tools' menu, and select 'Action Wizard'. Click on 'New Custom Command' in the toolbar.

2
Set up the JavaScript Execution

In the Custom Command dialog, click 'Command Options' and select 'Run a JavaScript'. This will open an editor window where you can input your script.

3
Input the Page Counting Logic

Write a script utilizing a loop from `pagenum = 0` to `this.numPages`. Inside the loop, use `this.getPageBox("Crop", pagenum)` to get the coordinates, and calculate the width and height.

4
Apply Tolerance and Tally

Create a helper function to compare the retrieved width and height against standard points (e.g., A3 is 841x1188, Legal is 612x1008, Letter is 594x792) with a tolerance of around 200 points. Increment specific counter variables (like `numA3` or `numUSL`) when a match is found.

5
Display the Results

Add an `app.alert()` statement at the end of your script to display the final counts for each size category, as well as the count of any unrecognized page sizes. Save the command and run it on your target PDF.

Create an Acrobat Custom Command using JavaScript
Orientation Support: By checking both (width against target width AND height against target height) OR (width against target height AND height against target width), your script will seamlessly handle both portrait and landscape pages.

Efficiently View and Manage PDF Pages with WPS Office

While Acrobat requires scripting for advanced page counting, WPS Office provides an intuitive visual interface for managing complex PDF documents. With powerful built-in page management tools, you can easily review page dimensions, extract specific pages, and organize your documents without needing to write a single line of code.

  1. 1. Open Your PDF: Launch WPS Office and open your multi-size PDF document in the WPS PDF reader.
  2. 2. Navigate to the Page Tab: Click on the 'Page' tab in the top navigation ribbon to access the comprehensive page management dashboard.
  3. 3. Inspect Page Sizes Visually: Use the thumbnail grid to quickly identify pages with different dimensions or orientations.
  4. 4. Manage and Extract Pages: Select pages by size and use the 'Extract' or 'Split' tools to separate them into distinct, uniformly sized documents.
Visual page management with easy-to-navigate thumbnail viewsBuilt-in PDF tools to crop, split, extract, and merge varying page sizesFully compatible with Adobe PDF standards and formatsLightweight, fast, and available across multiple operating systems
microsoft office alternative - wps office

Frequently Asked Questions

What unit of measurement does Acrobat JavaScript use for PDF page dimensions?

Acrobat JavaScript measures page dimensions in points (pts). There are exactly 72 points in one inch. For example, a standard US Letter page (8.5 x 11 inches) is approximately 612 x 792 points.

How does the script differentiate between portrait and landscape orientations?

To support both orientations, the script's logic should compare the page's width to the standard width and height to standard height, and then cross-compare (width to standard height, height to standard width). If either condition is met, the script recognizes the size.

Why do I need a tolerance or 'wiggle' value in my JavaScript?

PDFs created by different software applications or scanners may have slight rounding differences in their exact point sizes. Adding a tolerance (e.g., +/- 200 points) ensures that pages that are off by a fraction of an inch are still correctly categorized as standard sizes.

What happens to pages that do not match the standard sizes in the script?

If a page's dimensions fall outside of your specified standard sizes (like A3, Legal, or US Letter) and their tolerance ranges, the script registers it as 'unrecognized' and tallies it in an 'other pages' category.