When automating PDF processing using Python's PyMuPDF (fitz), redacting sensitive information like personally identifiable information (PII) or entity labels is a common task. However, developers often encounter a frustrating issue: applying redactions using page.search_for() and page.apply_redactions() sometimes erases parts of adjacent lines of text above or below the target phrase.

Why Does Redaction Clip Neighboring Text?

The issue occurs because page.search_for() returns a bounding box (a fitz.Rect object) that encompasses the full height of the target text line, including font ascenders and descenders. In documents with tight line spacing or line height overlaps, this bounding box slightly overlaps with the bounding box of characters on the line directly below or above it.

When page.apply_redactions() is executed, PyMuPDF permanently removes all vector content and text glyphs that intersect with the specified redaction rectangle. If the rectangle extends even a fraction of a point into the next line, characters on that line (like the top of the letter 'P' in 'Project') will be clipped out.

Solution 1: Adjust the Bounding Box Height (Recommended)

The simplest and most reliable fix is to slightly shrink the top and bottom edges of the target fitz.Rect before passing it to add_redact_annot(). Trimming a tiny vertical padding (e.g., 1 to 1.5 points) prevents the rectangle from touching neighboring line height boundaries without compromising the target text redaction.