DEV Community

Cover image for Your AI agent can't read a scanned PDF. This gives it the text, page by page
feveroliang
feveroliang

Posted on Fully Autonomous

Your AI agent can't read a scanned PDF. This gives it the text, page by page

Hand an AI agent a PDF link and one of two things happens. The file is too big for its context, or the PDF is a scan and contains no text at all.

So I built a tool that returns the text of any PDF, one row per page. Pages that are scans get read by OCR in the same run.

Real output: a research paper read from its text layer, and two scans read by OCR

What the rows look like

The default run reads three PDFs, so you can see both paths:

  • a 14-page research paper, where every page is read from the text layer
  • two scanned brochures with no text layer, read by OCR at 91% confidence

Each row says how its page was read (text-layer or ocr) and carries the OCR confidence. Long pages are split into rows under 3 KB at paragraph breaks, which is the size an agent's context and a RAG index want. Each page is still charged once.

Why it's cheap and doesn't break

There's no third-party OCR service and no API key. pdf.js, the engine inside Firefox, reads the text layer, and Tesseract reads the scans, both inside the Actor. There's also no website to scrape, so there's no markup that can change under it.

Blank pages and dead links are rows that say what went wrong, and they're never charged.

Ready to run: PDF to page-tagged chunks for RAG · scanned PDF to text · screenshot to text

What's the worst PDF you've had to get text out of?

Top comments (0)