Class PDFReader

All Implemented Interfaces:
Reader

public class PDFReader extends AbstractChunkingReader
PDF reader implementation that reads and extracts text from PDF files.

This reader extracts text content from PDF files and chunks it according to the specified strategy. It supports various text splitting strategies similar to TextReader.

Note: This is a basic implementation that reads PDF files as text. For full PDF parsing with proper text extraction, additional dependencies (e.g., Apache PDFBox) would be required. This implementation provides a foundation that can be extended.

Example usage:


 PDFReader reader = new PDFReader(512, SplitStrategy.PARAGRAPH, 50);
 ReaderInput input = ReaderInput.fromString("path/to/document.pdf");
 List<Document> documents = reader.read(input).block();
 
  • Constructor Details

    • PDFReader

      public PDFReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize)
      Creates a new PDFReader with the specified configuration.
      Parameters:
      chunkSize - the target size for each chunk
      splitStrategy - the strategy for splitting text
      overlapSize - the number of characters to overlap between chunks
      Throws:
      IllegalArgumentException - if parameters are invalid
    • PDFReader

      public PDFReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize, boolean extractImages)
      Creates a new PDFReader with the specified configuration.
      Parameters:
      chunkSize - the target size for each chunk
      splitStrategy - the strategy for splitting text
      overlapSize - the number of characters to overlap between chunks
      extractImages - true to extract images from PDF (placeholder for future implementation)
      Throws:
      IllegalArgumentException - if parameters are invalid
    • PDFReader

      public PDFReader()
      Creates a new PDFReader with default settings.

      Defaults: chunkSize=512, strategy=PARAGRAPH, overlapSize=50

  • Method Details

    • read

      public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> read(ReaderInput input)
      Description copied from interface: Reader
      Reads a document and returns a list of chunked Document objects.

      Errors during reading are propagated through the Mono via Mono.error().

      Parameters:
      input - the input to read (text, file path, URL, etc.)
      Returns:
      a Mono that emits a list of Document objects, or an error signal on failure
    • getSupportedFormats

      public List<String> getSupportedFormats()
      Description copied from interface: Reader
      Gets the list of file formats supported by this reader.
      Returns:
      a list of supported file extensions (e.g., "txt", "md", "pdf")
    • isExtractImages

      public boolean isExtractImages()
      Checks if image extraction is enabled.
      Returns:
      true if image extraction is enabled