PDF Reader
Convert local or remote PDF files into documents with PDFReader.
Pass PDFReader to Knowledge.insert() to configure PDF parsing and chunking.
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/activateInstall dependencies
uv pip install -U agno openai pgvector psycopg pypdf sqlalchemyExport the API key
export OPENAI_API_KEY=your_openai_api_key_hereRun 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:18Run the agent
python pdf_reader.pyReader Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
split_on_pages | bool | True | Create one document per page instead of one document for the whole file |
page_start_numbering_format | Optional[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_format | Optional[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 |
password | Optional[str] | None | Password to unlock encrypted PDFs |
sanitize_content | bool | True | Join fragmented lines from PDF text extraction into flowing text. Disable to preserve whitespace-sensitive content like code blocks or tables |
chunking_strategy | Optional[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
| Task | Guide |
|---|---|
| Choose a chunking strategy | Chunking |
| Process images with OCR | Readers Overview |
| Configure another reader | Docling Reader |