(macOS) Removing PDF Annotations and Highlights with pdfcpu

In daily office work, document organization, or archiving, PDF annotations such as highlights, comments, and sticky notes can affect readability and even expose sensitive information. This tutorial shows how to use the open-source command-line tool pdfcpu to batch remove all types of annotations from PDF files, making your documents "clean" as new.

Note: This tutorial applies only to macOS users.

PDF Annotations and Their Impact

PDF annotations (Annotations) include:

Clearing these annotations before sharing or archiving not only makes your documents look more professional but also prevents accidental leakage of comment information.

Prerequisites: Install pdfcpu

pdfcpu is a lightweight PDF processing tool. This tutorial is intended for macOS users. It is recommended to install it via Homebrew:

brew install pdfcpu

If you do not have Homebrew installed, please visit Homebrew's official site to install it first.

Remove Annotations with a Single Command

Use the following command to remove all types of annotations from a PDF file:

pdfcpu annotations remove -mode all input.pdf output.pdf

After execution, the generated output.pdf will contain no annotations.

If you omit output.pdf, the original file will be overwritten:

pdfcpu annotations remove -mode all input.pdf

Common Notice

If there are no annotations in the PDF, the terminal will display:

pdfcpu: RemoveAnnotations: No annotation removed

In this case, no file will be generated or modified.

Batch Processing Multiple PDFs

Combine a shell script to batch clear annotations from all PDF files in the current directory:

for file in *.pdf; do
  pdfcpu annotations remove -mode all "$file" "cleaned_$file"
done

This script will generate a new file with the cleaned_ prefix for each original PDF.

Important Notes

  1. File Backup: If you do not specify an output file, the original file will be overwritten. Always back up your documents before running these commands.
  2. Encrypted PDFs: Password-protected or encrypted PDFs must be decrypted before processing.
  3. Original Content: This command only removes annotations and will not modify the main content.
  4. Hidden Information: To further remove metadata or hidden information, see Remove Exif Metadata From Photos.

For more detailed PDF editing and processing, consider using PDF Reader and Editor.

For additional usage tips and advanced features, visit the pdfcpu project homepage and the official documentation.