PDF Reader

Convert local or remote PDF files into documents with PDFReader.

Pass PDFReader to Knowledge.insert() to configure PDF parsing and chunking.

pdf_reader.py
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.pdf_reader import PDFReader
from agno.models.openai import OpenAIResponses
from agno.vectordb.pgvector import PgVector

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

knowledge = Knowledge(
    vector_db=PgVector(
        table_name="pdf_documents",
        db_url=db_url,
    ),
)

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    knowledge=knowledge,
    search_knowledge=True,
)

if __name__ == "__main__":
    knowledge.insert(
        name="Thai Recipes",
        url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
        reader=PDFReader(split_on_pages=True),
    )
    agent.print_response(
        "How do I make chicken and galangal in coconut milk soup?",
        markdown=True,
    )

Run the Agent

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai pgvector psycopg pypdf sqlalchemy

Export the API key

export OPENAI_API_KEY=your_openai_api_key_here

Run PgVector

docker run -d \
  -e POSTGRES_DB=ai \
  -e POSTGRES_USER=ai \
  -e POSTGRES_PASSWORD=ai \
  -e PGDATA=/var/lib/postgresql \
  -v pgvolume:/var/lib/postgresql \
  -p 5532:5432 \
  --name pgvector \
  agnohq/pgvector:18

Run the agent

python pdf_reader.py

Reader Parameters

ParameterTypeDefaultDescription
split_on_pagesboolTrueCreate one document per page instead of one document for the whole file
page_start_numbering_formatOptional[str]"<start page {page_nr}>"Marker inserted at the start of each page when PDFReader detects a consistent printed page-number sequence. Set to an empty string to remove
page_end_numbering_formatOptional[str]"<end page {page_nr}>"Marker inserted at the end of each page when PDFReader detects a consistent printed page-number sequence. Set to an empty string to remove
passwordOptional[str]NonePassword to unlock encrypted PDFs
sanitize_contentboolTrueJoin fragmented lines from PDF text extraction into flowing text. Disable to preserve whitespace-sensitive content like code blocks or tables
chunking_strategyOptional[ChunkingStrategy]DocumentChunking()Strategy used to chunk documents

PDFReader also accepts the base Reader constructor parameters.

Use PDFReader.async_read() or Knowledge.ainsert() in an asynchronous ingestion path.

Next Steps

TaskGuide
Choose a chunking strategyChunking
Process images with OCRReaders Overview
Configure another readerDocling Reader