Skip to content

About

Extract highlights and annotations from PDF files (Apple Books compatible)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

PDF Highlight Extractor

A Python tool to extract highlights and annotations from PDF files, particularly useful for PDFs highlighted in Apple Books.

Features

  • Extract highlights, underlines, and other annotations from PDF files
  • Display highlighted text with page numbers
  • Include annotation notes/comments
  • Export to text or Markdown format
  • Save to file or display in console

Requirements

  • Python 3.6+
  • pymupdf (PyMuPDF)

Installation

  1. Clone or download this repository
  2. Install dependencies:
pip install pymupdf

Or if using the included virtual environment:

source .venv/bin/activate  # On macOS/Linux
pip install pymupdf

Usage

Basic usage (display in console):

python extract_highlights.py path/to/your/file.pdf

Save to a file:

python extract_highlights.py path/to/your/file.pdf -o highlights.txt

Save as Markdown:

python extract_highlights.py path/to/your/file.pdf -o highlights.md -f markdown

Command-line options:

  • pdf_file - Path to the PDF file (required)
  • -o, --output - Output file path (optional, prints to console if not specified)
  • -f, --format - Output format: text or markdown (default: text)

Examples

Extract highlights and display them:

python extract_highlights.py ~/Documents/mybook.pdf

Save highlights to a text file:

python extract_highlights.py ~/Documents/mybook.pdf -o mybook_highlights.txt

Save highlights as Markdown:

python extract_highlights.py ~/Documents/mybook.pdf -o mybook_highlights.md -f markdown

How it Works

The tool uses PyMuPDF (fitz) to:

  1. Open the PDF file
  2. Iterate through all pages
  3. Find annotation objects (highlights, underlines, etc.)
  4. Extract the text from the highlighted regions
  5. Collect any notes or comments attached to the highlights
  6. Format and output the results

Supported Annotation Types

  • Highlights
  • Underlines
  • Strikeouts
  • Squiggly underlines

Notes

  • This tool works with standard PDF annotations
  • Apple Books stores highlights as PDF annotations, making them compatible
  • The quality of extracted text depends on the PDF structure
  • Some PDFs may have image-based text that cannot be extracted

License

MIT

Contributing

Feel free to submit issues or pull requests for improvements!

About

Extract highlights and annotations from PDF files (Apple Books compatible)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages