Annotate and Highlight PDFs with PyMuPDF
Harald Lieder·June 20, 2025

Why Annotation Matters
Annotations and highlights have become indispensable in modern workflows. Whether in academia, legal proceedings, or collaborative document reviews, markup tools help teams streamline feedback and enhance readability.
Annotating PDFs goes beyond simple markup: it enables precise interaction with digital text. Professionals use these tools to emphasize contract clauses, researchers highlight critical passages, and students engage dynamically with study materials.
Typical Use Cases
Annotation plays a key role in:
Academic Peer Review: Researchers collaboratively review manuscripts, marking important findings or suggesting edits.
Contract Negotiation: Legal professionals highlight clauses, add strikeouts, and provide context-sensitive comments.
Document Feedback Cycles: Business teams refine reports, proposals, and presentations with structured markup.
How PyMuPDF Enhances PDF Annotation
PyMuPDF offers powerful tools for adding highlights, comments, and annotations programmatically. Its flexibility allows developers to automate markup creation and tailor annotations for various use cases.
Key Features:
Precise Text Search: PyMuPDF retrieves hit rectangles of matching text, even when the text is non-horizontal.
Multi-Line Highlighting: Supports highlights across multiple lines, specifying start and stop positions within lines.
Advanced Highlighting Styles: Includes standard highlights, strikeouts, underlines, and zigzag underlining for diverse annotation needs.
Compatibility: Annotations created with PyMuPDF are visible in any standard PDF reader, ensuring seamless document exchange.
Code Example: Searching for Text and Highlighting Hits
Here’s a Python example using PyMuPDF to search for text and highlight the detected locations:
import pymupdf
# Load the PDF file
doc = pymupdf.open("sample.pdf")
# Define the search term
search_text = "important clause"
# Iterate through pages
for page in doc:
# Search for the text
text_instances = page.search_for(search_text, quads=True)
# Apply different types of highlighting
for inst in text_instances:
page.add_highlight_annot(inst) # Standard highlight
page.add_strikeout_annot(inst) # Strikeout
page.add_underline_annot(inst) # Underline
page.add_squiggly_annot(inst) # Zigzag underline
# Save the modified PDF
doc.save("annotated.pdf")
The above will automatically support non-horizontal text because parameter quads=True
delivers tilted rectangles if text is not axis-aligned.
For multi-line highlights, identify two points on the page which represent the start, respectively stop positions. The highlighting statement then takes on this format:
add_highlight_annot(start=start_point, stop=stop_point)
This will highlight all text enclosed by the given points.
Why Developers Choose PyMuPDF
For developers integrating annotation capabilities, PyMuPDF provides an efficient, lightweight solution. It enables programmatic markup creation while maintaining flexibility in text positioning and highlight formatting.
Whether you’re automating document reviews or building an interactive reading application, PyMuPDF empowers you to enhance PDFs with precise annotations.
For further details please refer to the articles Highlighting Text With PyMuPDF and Explore Text Searching With PyMuPDF.