PDFOCRRAG

The PDF is searchable. Its lot number is still missing.

A mixed PDF can contain native text and a bitmap label on the same page. Extract each region of a downloadable receiving note and verify that LOT K47 survives indexing.

The PDF is searchable. Its lot number is still missing.

Searching for “packing slip” works. Searching for the lot number printed underneath it doesn't. Both are visible on the same page, but only the first is native text. A pipeline that skips OCR whenever a page yields any text will miss the label entirely.

Establish what the text layer contains

In the sample receiving note, Receiving note and Keep the packing slip. are page text. LOT K47 is a bitmap. With pypdf 7.2.0, PdfReader("mixed.pdf").pages[0].extract_text() returned the title and instruction, with no K47. The pypdf extraction guide explains why reading text and recognizing pixels are separate operations.

The rendered PDF shows the receiving instruction and LOT K47 together

Read the smallest region that answers the question

Render the label at a known resolution and pass that crop to Tesseract. From the directory containing the sample, run the following with Poppler, Tesseract and English language data installed. The rectangle uses pixels at 144 DPI, not PDF points, and belongs only to this fixture.

pdftoppm -f 1 -l 1 -singlefile -r 144 -x 60 -y 276 -W 840 -H 120 -png mixed.pdf lot
tesseract stdin stdout -l eng --psm 7 < lot.png

Tesseract 5.5.0 returned LOT K47 locally. We tested a clean printed English label, not handwriting or a multilingual capture. Keep its page, crop and OCR origin with the value. An identifier is an unforgiving test: K4T is a plausible string and the wrong lot.

Native text passes through; only the label travels through image recognition

Should the whole document go through OCR again?

Keep intact native text when you can identify the missing regions. For a document-wide alternative, OCRmyPDF's advanced guide distinguishes skipping pages with text from redoing OCR while masking visible text and recognizing additional content. Skipping a mixed page leaves its bitmap untouched. We did not run OCRmyPDF for the crop experiment.

After merging results, check that the original instruction occurs once, the identifier matches the pixels character by character, and retrieving it takes you back to the right label. Route an illegible character for review rather than completing the identifier from nearby records. At larger scale, block-level confidence can help prioritize review.

Three acceptance checks: no duplicate text, exact identifier and a traceable region

A value inside a clickable field is a different case: read the PDF form data before trying OCR. If all the words survive extraction but the answer has no source, trace the citation pipeline instead.

Related posts

Run your Agent workflow through Nbility

Get an API key and connect OpenAI-compatible models and developer tools from one place.

Get an API key