Skip to main content
@talosjs/pdf is a PDF content extraction toolkit built on @firecrawl/pdf-inspector. A single PDF class, pointed at a file path, classifies the document (text-based, scanned, image-based, or mixed), converts it to Markdown, and tells you which pages it couldn’t extract text from so you can route them to OCR.

Installation

Add the package to your project with Bun.

Usage

Create a PDF instance with the path to a file, then call extract().

Restricting extraction to specific pages

Pass pages with 0-indexed page numbers, in the order you want them extracted.

Routing pages to OCR

Text-based pages come back as Markdown directly. Pages the extractor couldn’t get clean text from are listed in pagesNeedingOcr, with the reason for each in ocrReasonsByPage, so you can send just those pages through an OCR pipeline.
@talosjs/rag builds directly on this: its RAG class calls PDF.extract() and automatically OCRs the pages it flags, via OpenRouter. See PDF Extraction.

The result shape

extract() returns a PDFExtractResultType:

Exceptions

PDFException is thrown when extraction fails, for example when the file doesn’t exist or can’t be read. It carries a machine-readable key (such as PDF_EXTRACT_FAILED) and the source path in its data.

What it handles

It reads uploaded or stored PDFs and turns them into clean Markdown for search, indexing, chunking, or feeding to an LLM, while telling you exactly which pages need OCR instead of guessing. What it isn’t built for is authoring, editing, or rendering PDFs — generating documents, splitting files, or converting pages to images. That’s a job for a dedicated PDF-generation library.