How to Count the Number of Pages in Multiple PDFs on Mac

If you need to count pages in multiple PDFs on your Mac, this guide is for you. We’ll cover three simple ways to view both individual and total page counts. Plus, we’ll show you how to create a small app for quick page counts in the future—no extra steps required.


If you’ve ever had a collection of PDF files—maybe a set of chapters, reports, or documents—and you needed to know the total number of pages, you might have found yourself clicking through each file just to get the page count. This task can be tedious, especially if you have many PDFs.

Luckily, on a Mac, there are ways to automate this process, and you don’t need to be a tech expert to do it! Also, the methods outlined in this post use either Mac’s native or freely available software.

In this guide, we’ll look at three methods to count pages across multiple PDFs. First, we’ll see a simple method, then we’ll cover using a tool called GhostScript, which is handy for manipulating PDFs using the Terminal, as well as AppleScript, a built-in Mac feature that allows you to run a script to do a variety of tasks in just a few clicks.

Don’t worry if you’re not familiar with these tools—each step is explained clearly, so anyone can follow along.

Let’s dive in!

Method 1: Combine All PDFs

The most straightforward, no-fuss method on Mac to get the number of pages in hundreds of PDFs is to combine all of them into a single PDF and then open it in a PDF reader. This approach allows you to easily view the total page count at a glance without the need for any additional software or scripts.

How to Combine PDFs

Step 1: Select the PDFs:

Navigate to the folder containing your PDFs, select all the files (Cmd+A) you want to combine. You can also hold down the Command (⌘) key and click individual PDF to select particular files.

Step 2: Combine them

With all the PDFs selected, right click → Quick Actions → Create PDF.

You can combine or merge multiple pdf files on Mac by selecting them, right click → Quick Actions → Create PDF. The PDF is created without you needing to install any other software or tool.

Step 3: Give it a name

A new PDF file will be created and you will be asked to name it. Give it an appropriate name and open it in your PDF viewer or just press Cmd + O to open it. (Its Command + O, not zero)

The total number of pages in the PDF will be displayed in the toolbar at the top.

Method 2: Using GhostScript to count pages in multiple PDFs

GhostScript is a powerful tool for working with PDFs on your Mac. It runs in the Mac terminal.

Even if you’re new to using the Terminal, don’t worry—we’ll walk through each step carefully to help you count pages in multiple PDFs quickly and easily. This method is great for getting both the individual page counts of each PDF file and a total count for the whole set.

Step 1: Install GhostScript

If you haven’t installed GhostScript yet, you’ll need to do this first. The easiest way is through Homebrew, a free package manager for Mac.

  1. Open Terminal (found in Applications > Utilities).
  2. Type the following command to install Homebrew if you haven’t already:
Bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once Homebrew is installed, enter this command to install GhostScript:

Bash
brew install ghostscript

This will set up GhostScript, so you’re ready to start counting pages.

Step 2: Run the GhostScript Command

Now that GhostScript is installed, we’ll use it to count pages. Here’s a command that will go through each PDF in a folder and display the page count for each file, followed by a total page count.

In Terminal, copy and paste the following command. Make sure to replace “/path/to/pdf/folder” (keep the double quotes) with the path to the folder containing your PDFs.

Bash
total=0
for file in "/path/to/pdf/folder"/*.pdf; do 
    pages=$(gs -q -dNOSAFER -dNOPAUSE -dBATCH -dNODISPLAY -c "(${file}) (r) file runpdfbegin pdfpagecount = quit")
    echo "$file: $pages pages"
    total=$((total + pages))
done
echo "Total pages in all PDFs: $total"

Press Enter to run the command. The script will display the page count for each PDF and then show the total count at the end.

GhostScript allows you to see the page count of multiple PDF files with varying flexibility.

And that’s it! This command provides a quick way to get an overview of the page counts in all your PDFs without needing to open each file individually.

(You definitely want to be careful about running any random script you find online in your terminal. I’ve tested this one myself, and it works as it should. Still, if you’re a bit iffy about it, feel free to copy the code and ask ChatGPT to break it down for you.)

Now, let’s look at another way to achieve the same result using AppleScript.

Counting pages in multiple PDFs using AppleScript

If the Terminal feels a bit intimidating, AppleScript is a more user-friendly option built right into your Mac. This method allows you to count pages in multiple PDFs with just a few clicks, making it ideal for those who prefer a straightforward approach. You’ll create a simple script that can be saved and reused whenever you need to count pages.

Step 1: Open Script Editor

  1. Navigate to Applications > Utilities and open Script Editor. Alternatively, open Spotlight (Cmd + Space) and search for Script Editor.

This program allows you to write and run AppleScripts easily.

Step 2: Write the AppleScript

Now, you’ll enter a script that counts the pages in all the PDFs in a selected folder.

In the Script Editor, erase any existing text and copy and paste the following code:

AppleScript
set totalPages to 0
set pdfFolder to choose folder with prompt "Select the folder containing your PDF files"
tell application "Finder"
	set pdfFiles to (every file of pdfFolder whose name extension is "pdf")
	repeat with pdfFile in pdfFiles
		set filePath to (pdfFile as alias)
		set pageCount to (do shell script "mdls -name kMDItemNumberOfPages " & quoted form of POSIX path of filePath)
		set pageCount to word 3 of pageCount as integer
		set totalPages to totalPages + pageCount
	end repeat
end tell
display dialog "Total number of pages: " & totalPages

Step 3: Run the Script

Click the Run button (looks like a play icon) in the Script Editor toolbar.

Apple script is a flexible way to interact with the Mac filesystem and utilities. It also allows you to save these scripts as standalone applications which can be run directly without any other intermediate steps.

A dialog box will prompt you to select the folder containing your PDFs. Choose the appropriate folder. The script will then run for some time (depending on number of pdfs you chose and tell you the total count of pages in all pdfs combined).

Once you run the script, a dialog box will pop up displaying the total number of pages across all the PDFs in the selected folder.

Step 4: Save as an Application (Optional)

To make this process even easier for future use, you can save the script as an application:

  1. Go to File > Export in the Script Editor.
  2. Select Application as the file format, give it a name (e.g., “PDF Page Counter”), and choose a location to save it.

Now, you can double-click this application anytime you want to count pages without having to go through the Script Editor again!

Using AppleScript allows you to quickly and effectively count pages in your PDFs without delving into Terminal commands, making it a perfect solution for beginners.

Conclusion

Counting pages in multiple PDFs on your Mac doesn’t have to be a daunting task. Whether you prefer a simple and visual approach by combining PDFs or want to explore the more technical options with GhostScript and AppleScript, each method has its advantages tailored to different comfort levels and needs.

The combining method is perfect for those who appreciate a straightforward solution, while GhostScript and AppleScript offer powerful ways to automate the counting process, making it easy to handle large collections of documents.

Whichever method you choose, you’ll find that managing PDF page counts becomes a quick and efficient task. Now you’re equipped with the tools to handle your PDFs like a pro! Happy counting!