pdfdol.checks#

Checks that verify a PDF, rather than looking at a few of its pages.

text_overlaps finds text lines whose boxes overlap, the signature of a broken pagination (a block drawn on top of another). It needs PyMuPDF, which is part of the figures (and chromium) extra of pdfdol.

Functions

text_overlaps(pdf, *[, min_frac, snippet_len])

Pages (1-based) with text lines that overlap, and the pairs of overlapping lines.

pdfdol.checks.text_overlaps(pdf, *, min_frac=0.3, snippet_len=40)[source]#

Pages (1-based) with text lines that overlap, and the pairs of overlapping lines.

Two lines overlap when the area they share is at least min_frac of the smaller line’s area. An empty dict means no overlapping text.

Parameters:
  • pdf – path, bytes, or an open PyMuPDF document.

  • min_frac (float) – overlap threshold, as a fraction of the smaller line box.

  • snippet_len (int) – how many characters of each line to report.

Return type:

dict[int, list[tuple[str, str]]]

>>> import io
>>> from reportlab.pdfgen import canvas
>>> def make(y2):
...     buf = io.BytesIO(); c = canvas.Canvas(buf)
...     c.drawString(72, 700, "first line of text"); c.drawString(72, y2, "second line of text")
...     c.save(); return buf.getvalue()
>>> text_overlaps(make(100))
{}
>>> text_overlaps(make(699))
{1: [('first line of text', 'second line of text')]}