How to Extract First Page from Multiple PDFs

If you want to extract the first or any particular page from multiple PDFs, this article is for you. In this guide, you will learn how to extract specific pages from PDFs and manipulate them.


Have you ever found yourself needing to extract just the first page—or any specific page—from a collection of PDF documents? It’s easy enough when you’re dealing with just a few PDFs, but what if there are hundreds or even thousands?

Luckily, there are straightforward methods available that can make this process simple and efficient, even for those who aren’t comfortable with technical commands or scripts.

In this guide, we’ll explore how to extract the first page or any particular page from multiple PDFs using an excellent PDF manipulation tool called GhostScript.

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

Install GhostScript

Before we can extract pages from PDFs, we need to have GhostScript installed on your system. GhostScript is a versatile tool that helps you manipulate PDF files. It is free and available for all platforms, Mac, Windows and Linux. You can download it from here.

However, if you are on a Mac, the best way to download it is using Homebrew, the package manager for Mac and Linux. Installing it via Homebrew makes the process quick and easy.

Here’s step by step guide:

Step 1: Open Terminal

You can find Terminal by going to Applications > Utilities > Terminal, or by searching for it using Spotlight (press Command (⌘) + Space and type “Terminal”).

Step 2: Install Homebrew

If you don’t have Homebrew installed yet, you can easily install it by entering the following command in the Terminal:

Bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Press Enter and follow the on-screen instructions to complete the installation. This might take a few minutes.

Step 3: Install GhostScript:

Once Homebrew is set up, you can install GhostScript by typing the following command in the Terminal:

Bash
brew install ghostscript

Hit Enter to execute the command. Homebrew will download and install GhostScript for you.

Verify the Installation: After the installation is complete, you can confirm that GhostScript is installed by typing:

Bash
gs --version

This command will display the installed version of GhostScript, indicating that the installation was successful.

gs --version command shows the version number of ghostscript

Now that you have GhostScript installed on your Mac, you’re ready to start extracting pages from your PDF files! The next sections will guide you through the process of using GhostScript for this task.

Using GhostScript to extract first page from multiple PDFs

Now that GhostScript is installed on your Mac, you can easily extract the first page from multiple PDF files. This process allows you to create new PDFs that contain just the first page of each document, making it simple to gather information without the clutter of unnecessary pages.

Also read: How to Open Multiple PDFs in the Arc Browser

(The following commands are for MacOS. These commands for Windows will vary slightly, mostly due to its different file path conventions. So, make sure to tweak them when using them on Windows.)

Step-by-Step Guide to Extracting the First Page

  1. Prepare Your PDFs:
    Place all the PDF files from which you want to extract the first page into a single folder. This will make it easier to run the command for multiple files.
  2. Open Terminal:
    If you haven’t already, open the Terminal application (found in Applications > Utilities), or use the Spotlight (Cmd + Space) and then type ‘Terminal’
  3. Navigate to Your folder:
    Use the cd command to change to the directory where your PDFs are located. For example:
Bash
cd /path/to/your/pdf/folder

Replace /path/to/your/pdf/folder with the actual path to the folder containing your PDF files. If your path or folder contains any space, put the path in quotes, like this:

Bash
cd "/path/to/your/pdf/folder"

If you’re unsure about the path, you can drag and drop the folder into the Terminal window to automatically fill in the path.

4. Run the GhostScript Command:
Now you can use GhostScript to extract the first page from each PDF file. Enter the following command in the Terminal:

    Here’s what this command does:

    • for file in *.pdf; do : starts a loop that goes through each PDF file in the folder.
    • gs -q -dNOPAUSE -dBATCH runs GhostScript quietly without pausing.
    • -sDEVICE=pdfwrite specifies that we want to create a PDF file.
    • -sOutputFile="first_page_${file}" names the output file, adding “first_page_” to the original file name.
    • "$file" refers to the current file being processed.
    • -dFirstPage=1 -dLastPage=1 tells GhostScript to extract only the first page. (we will talk about it a little more).

    5. Check Your Output:
    After running the command, you should see new PDF files created in the same folder. Each new file will contain just the first page of the original document, named with the prefix “first_page_”.

    The extracted PDFs with particular page: Extract first page from multiple pdfs using GhostScript

      This method provides a quick way to gather the first pages from multiple PDFs without needing to open each one individually. In the next section, we’ll talk about how to extract any specific page from your PDF files.

      Extract particular page(s) from PDFs

      In addition to extracting the first page from your PDF documents, GhostScript offers flexible options for extracting any specific page or range of pages. This versatility allows you to tailor the extraction process to meet your needs, whether you want a single page or a group of pages from each PDF.

      Also read: How to open 4 tabs side-by-side on Mac

      Below, we’ll explore various ways to use GhostScript commands to achieve this.

      Extracting a Single Specific Page

      If you want to extract a specific page, simply modify the -dFirstPage and -dLastPage parameters in the command. For example, if you want to extract the third page from each PDF, you would use:

      Bash
      for file in *.pdf; do gs -q -dNOPAUSE -dBATCH -dFirstPage=3 -dLastPage=3 -sDEVICE=pdfwrite -sOutputFile="third_page_${file}" -f "${file}"; done

      Extracting a Range of Pages

      If you need to extract a range of pages, for example, pages 5 to 7, you can adjust the command like this:

      Bash
      for file in *.pdf; do gs -q -dNOPAUSE -dBATCH -dFirstPage=5 -dLastPage=7 -sDEVICE=pdfwrite -sOutputFile="pages_5to7_${file}" -f "${file}"; done

      Custom Output Filenames

      You can further customize the output filenames to reflect the pages extracted. For instance, if you want to name your output file according to the extracted pages, you could do:

      Bash
      for file in *.pdf; do gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="pages_${page_range}_${file}" "$file" -dFirstPage=2 -dLastPage=5; done

      In this case, replace ${page_range} with the actual range you’re extracting (e.g., “2_to_5”).

      Extracting Pages from Multiple PDFs into One

      If you want to extract the same pages from multiple PDFs and combine them into a single PDF, you can first extract the pages individually and then merge them. To extract the same pages from multiple PDFs (say pages 2 and 3), you would execute:

      Bash
      for file in *.pdf; do
      	gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="extracted_${file}" "$file" -dFirstPage=2 -dLastPage=3;
      done

      After that, you can combine these extracted files using another GhostScript command:

      Bash
      gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="combined_extracted_pages.pdf" extracted_*.pdf

      Here’s a brief summary of various options we discussed so far:

      • Extract a Specific Page: Adjust -dFirstPage and -dLastPage to the same page number.
      • Extract a Range of Pages: Set -dFirstPage to the start page and -dLastPage to the end page of your desired range.
      • Custom Output Names: Modify the output file names to reflect the content.
      • Combine Extracted Pages: After extracting, merge them into one PDF for easier access.

      Also read: Useful Browser Extensions for Excalidraw

      Conclusion

      Extracting specific pages from multiple PDF files doesn’t have to be a daunting task, even for those who may not feel comfortable using command-line tools. With GhostScript, we’ve explored straightforward methods for not only pulling out the first page of each document but also for extracting any page or range of pages you need.

      Remember, GhostScript is flexible, so you can bend it to do almost anything you wish. If nothing comes to mind, ask ChatGPT. That will help.