← All tools

File I/O

PDF Read

Extract text from PDFs with page ranges.

pdf_read

Overview

Reads PDF documents — annual reports, research papers, legal contracts — and extracts the text inside so the agent can summarise, search, or quote it. Works even for long multi-page documents.

How it works

Opens the PDF at the supplied path using Apache PDFBox and extracts the text and basic metadata. Accepts optional 'startPage' and 'endPage' parameters to read just a range — useful for large documents that would otherwise blow through the context window.

Example

When a user asks:

Extract the first 5 pages of annual-report.pdf.

the agent calls the tool:

pdf_read(path="annual-report.pdf", startPage=1, endPage=5)

and gets back: the plain-text content of those pages plus basic metadata.

Use it in a workflow

Wire this tool into a SwarmAI crew. Use the YAML DSL for declarative workflows, or the Java builder API when you want full programmatic control.

YAML DSL

# document-review.yaml
name: document-review-crew
process: SEQUENTIAL

agents:
  - id: analyst
    role: Document Analyst
    goal: Extract text from PDF documents
    tools:
      - pdf_read

tasks:
  - id: document-review-task
    agent: analyst
    description: Read pages 1-5 of annual-report.pdf and summarize the opening letter.

Java

import ai.intelliswarm.swarmai.agent.Agent;
import ai.intelliswarm.swarmai.task.Task;
import ai.intelliswarm.swarmai.swarm.Swarm;
import ai.intelliswarm.swarmai.swarm.SwarmOutput;
import ai.intelliswarm.swarmai.process.ProcessType;
import ai.intelliswarm.swarmai.tool.common.PDFReadTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;

@Autowired ChatClient chatClient;
@Autowired PDFReadTool pDFReadTool;

Agent analyst = Agent.builder()
    .role("Document Analyst")
    .goal("Extract text from PDF documents")
    .chatClient(chatClient)
    .tool(pDFReadTool)
    .build();

Task analystTask = Task.builder()
    .description("Read pages 1-5 of annual-report.pdf and summarize the opening letter.")
    .agent(analyst)
    .build();

SwarmOutput result = Swarm.builder()
    .agent(analyst)
    .task(analystTask)
    .process(ProcessType.SEQUENTIAL)
    .build()
    .kickoff();

What it's good for

Real scenarios where agents put this tool to work.

Extracting research-paper text from PDFs fetched via arxiv_search
Annual-report / 10-K PDF ingestion for finance crews
Legal and contract review agents
Page-ranged reads on large PDFs to stay within context

Source

Implementation lives at swarmai-tools/src/main/java/ai/intelliswarm/swarmai/tool/common/PDFReadTool.java in the swarm-ai repository.

Open pdf_read on GitHub →