Datagrunt 5.6.0: Flagging Occluded, Clipped & Blank-Glyph Hidden PDF Text

November 23, 2026by Martin Graham

Datagrunt 5.6.0 is now available! This minor release closes Issue #395 by closing the remaining blind spots in PDF hidden-text detection (PR #524).

Until now, Datagrunt’s PDF quality stage flagged nine hidden_reasons (off_page, invisible, tiny_font, transparent, matches_background, zero_scale, duplicate, superseded, and unchecked_background). Three visual hiding techniques could still slip past as seemingly visible text: text covered later in paint order by an opaque shape or raster image, text excluded by a PDF clipping path, and non-whitespace glyphs whose Type3 font CharProc draws no outline or visible ink.

Datagrunt 5.6.0 appends occluded, clipped, and blank_glyph to HIDDEN_REASONS—preserving the canonical order of the original nine reasons—and enforces every zero-false-positive safeguard needed for real-world tables, CAD drawings, and OCR layers.


Highlights in Datagrunt 5.6.0

  1. occluded Detection — Tracks opaque filled paths (including culled paths under 11.9 pt) and candidate opaque raster images in page paint order, indexing them into narrow/wide x0-sorted horizontal bands and pairing geometric sampling with a guarded BGR visibility diff for raster images.
  2. clipped Detection — Evaluates nested PDF clipping paths and enclosing Form XObject clips across all page rotations (/Rotate 0/90/180/270), flagging characters whose glyphs fall completely outside their active clip region while splitting partially clipped spans cleanly.
  3. blank_glyph Detection — Flags non-whitespace, non-control/separator characters in painting render modes when their glyph outline collapses to PDFium’s stand-in box or when a Type3 glyph declares a non-zero d1 box yet paints no ink in a guarded with_text vs. without_text render diff.
  4. CAD, Highlight & OCR Zero-False-Positive Safeguards — Hollow border frames, translucent or /Multiply highlighters, /SMask overlays, 1 pt strikethrough/underline bars, enclosing CAD viewport clips, and 3 Tr AutoCAD SHX stroke-backed text stay visible.
  5. Full Pipeline & rationalize() Integration — All 12 HIDDEN_REASONS are preserved in PDFDocument, DataFrames, JSON, JSONL, CSV, Parquet, and to_markdown(include_hidden=True), omitted from default Markdown, and automatically excluded from LLM prompt envelopes in rationalize() and rationalize_many().

1. Paint-Order Occlusion (occluded)

A common PDF obfuscation and whiteout pattern draws text first and then paints an opaque rectangle, polygon, or raster image over the same coordinates later in the page stream. Because PDFium’s textpage still extracts the underlying text, naive parsers treat that covered text as readable content.

In Datagrunt 5.6.0, the fused page-object walk records opaque paint objects in paint order:

  • Opaque filled paths: Any non-transparent filled path (fill_rgba[3] == 255 with no object or enclosing Form XObject transparency, up to 1024 segments and 8,000 occluders per page), including small fills under 11.9 pt that are culled from table lattice segments.
  • Exact polygon & curve handling: Axis-aligned rectangles are evaluated directly by bounding box; non-rectangular shapes (such as diamonds or triangles) and cubic Bézier paths are flattened in display coordinates and tested under PDF’s even-odd (FPDF_FILLMODE_ALTERNATE) or nonzero winding rules, respecting each occluder’s own effective clip region.
  • Spatial indexing for O(log N) lookups: Occluders are partitioned into 32 pt horizontal y-bands (capped at 4096 bands) and split into narrow (<= 64 pt) and wide (> 64 pt) x0-sorted lists with prefix-max x1 arrays so a single full-page background fill never degrades lookups to quadratic time.
  • 9-point inset sampling with bounded budget: Each non-whitespace character’s tight_box is tested at a 3×3 inset grid (0.2, 0.5, 0.8 across width and height). A character is flagged occluded when at least 8 of 9 sample points are covered by occluders with a strictly greater object_index. Per-page occlusion checks are capped at 500,000 (MAX_OCCLUSION_CHECKS), failing open rather than risking quadratic stalls on pathological pages.
  • Guarded raster image disambiguation: When a visible span is covered by a later candidate raster image (where an /SMask or internal transparency might let text show through), Datagrunt runs a guarded paired BGR render (with_text vs. without_text, honoring max_render_pixels and the 2 GiB worker memory cap in both in-process and sandbox=True modes). Characters whose tight box shows no RGB channel difference greater than 4 between the two renders are flagged occluded.

Zero-False-Positive Protections

Real documents routinely draw shapes and bars over or around visible text. Datagrunt 5.6.0 explicitly keeps all of the following visible:

  • Earlier backgrounds: Fills and images drawn before the text (occ.object_index <= span.object_index).
  • Translucent & blend-mode overlays: Semi-transparent highlights (ca < 1.0) and /Multiply highlighter fills (FPDFPageObj_HasTransparency).
  • /SMask raster overlays: Images carrying an alpha soft mask that leaves underlying ink visible in the paired render diff.
  • Hollow border frames: Even-odd (f*) or nonzero-winding frames drawn around table cells.
  • 1 pt strikethrough & underline bars: Thin rules that cover fewer than 8 of the 9 inset sample points.
  • Clipped-away fills: Later opaque fills whose active clip path excludes the text region.

2. PDF Clipping Paths (clipped)

Text placed outside an active PDF clipping path (W / W* followed by n) or outside a Form XObject’s /BBox paints zero pixels on the page, yet remains present in the text stream.

Datagrunt 5.6.0 extracts per-object clipping geometry across the entire page tree:

  • Nested clip & Form XObject intersection: Walks Form XObjects and page objects once, composing inherited transforms, Form /BBox boundaries, and up to 16 nested clip paths per object (256 segments each, flattening cubic Bézier curves) in display space across /Rotate 0, 90, 180, and 270.
  • Zero-area, disjoint, and 7 Tr clips: Zero-area clips (0 0 0 0 re W n) and disjoint nested clips flag contained text as clipped, while 7 Tr text-only clipping states remain unclipped for text while suppressing opaque occluder emission.
  • 0-of-9 sampling with hairline tolerance: A non-whitespace character is flagged clipped only when 0 of its 9 inset sample points lie inside the active ClipRegion (evaluated with a 0.5 pt hairline tolerance).
  • Partial clip splitting & CAD viewports: Enclosing CAD viewport clips leave interior text untouched, while a clip boundary cutting across a span splits it cleanly into visible and clipped pieces.

3. Blank & Zero-Paint Type3 Glyphs (blank_glyph)

A PDF can map a character code via /ToUnicode (for example, injecting "IGNORE ALL") onto a Type3 glyph whose CharProc paints nothing: either declaring 0 0 0 0 d1 or declaring a non-zero bounding box (600 0 50 50 550 650 d1, a “lying d1”) with an empty path stream.

Datagrunt 5.6.0 catches both variants without false positives on CAD or OCR text:

  • Collapsed stand-in box check: When a non-whitespace, non-control/separator character (excluding U+FFFD and collapsed-em spans) in a painting render mode collapses to PDFium’s <= 0.0025 * em stand-in box (for em >= 1.0 pt), it is flagged blank_glyph directly in pure geometry.
  • Guarded Type3 visibility diff: For painting, non-collapsed Type3 spans (base_font_name == ""), Datagrunt checks the paired with_text vs. without_text BGR renders. Characters that produce no pixel ink difference (<= 4 per BGR channel) are flagged blank_glyph, splitting mixed Type3 spans cleanly into visible prefixes and blank_glyph suffixes—even when the font uses /Encoding /Differences without a /ToUnicode map.
  • Strict 3 Tr / 7 Tr exemption: No-paint render modes 3 and 7—including AutoCAD SHX searchable text overlays backed by vector strokes with zero tight glyph boxes, as well as OCR text layers—are strictly exempted from blank_glyph.

4. Inspecting All 12 HIDDEN_REASONS in Python

Like every other hidden-text classification in Datagrunt 5.x, occluded, clipped, and blank_glyph are flagged, never dropped. Contiguous runs of characters sharing the same reasons are bridged across interior whitespace so hidden phrases stay intact rather than fracturing word by word.

import polars as pl
from datagrunt import PDFReader, PDFWriter
from datagrunt.pdf import HIDDEN_REASONS

print("Canonical hidden reasons:", HIDDEN_REASONS)

reader = PDFReader("document.pdf")

# Default Markdown omits all hidden elements so readers see only visible text
visible_md = reader.to_markdown()

# Pass include_hidden=True to audit every hidden element behind <!-- hidden: reasons -->
audit_md = reader.to_markdown(include_hidden=True)

# Filter the Polars DataFrame by specific hidden_reasons
df = reader.to_dataframe()
visible_df = df.filter(pl.col("hidden_reasons").list.len() == 0)
hidden_395 = df.filter(
    pl.col("hidden_reasons").list.contains("occluded")
    | pl.col("hidden_reasons").list.contains("clipped")
    | pl.col("hidden_reasons").list.contains("blank_glyph")
)

# JSON, JSONL, CSV, Parquet, and bundles preserve all elements and their flags
PDFWriter(reader.document).write_jsonl("out/elements.jsonl")

Automatic Exclusion in rationalize()

When using schema-driven extraction (rationalize() or rationalize_many()), elements carrying any of the 12 HIDDEN_REASONS are automatically stripped before LLM prompt construction and tracked in result.telemetry.hidden_excluded_by_reason:

from typing import Annotated
from pydantic import BaseModel
from datagrunt import Key, PDFReader, rationalize


class PartRecord(BaseModel):
    part: Annotated[str, Key]
    name: str
    qty: int


doc = PDFReader("parts_spec.pdf").document
result = rationalize(
    doc,
    schema=PartRecord,
    prompt="Extract part number, name, and quantity.",
    models=("openai:gpt-5.4", "anthropic:claude-sonnet-4-6"),
    min_families=2,
)

print("Excluded hidden counts:", dict(result.telemetry.hidden_excluded_by_reason))

Upgrading to Datagrunt 5.6.0

Upgrade with uv:

uv pip install --upgrade "datagrunt[pdf,rationalize]"

Or with pip:

pip install --upgrade "datagrunt[pdf,rationalize]"

For full details on all 12 hidden-text reasons and extraction routing, see the PDF Parsing Guide and Migrating to 5.0.