Class ApachePdfBoxDocumentParser.Builder

java.lang.Object
dev.langchain4j.data.document.parser.apache.pdfbox.ApachePdfBoxDocumentParser.Builder
Enclosing class:
ApachePdfBoxDocumentParser

public static final class ApachePdfBoxDocumentParser.Builder extends Object
Builder for ApachePdfBoxDocumentParser. Options that are not set (or set to null) use their default values.
Since:
1.25.0
  • Method Details

    • includeMetadata

      public ApachePdfBoxDocumentParser.Builder includeMetadata(@Nullable Boolean includeMetadata)
      Sets whether the metadata of the PDF file (for example its author or creation date) is added to the parsed Document.
      Parameters:
      includeMetadata - whether to include the metadata; null means the default, false
      Returns:
      this builder
      Since:
      1.25.0
    • maxCharacters

      public ApachePdfBoxDocumentParser.Builder maxCharacters(@Nullable Integer maxCharacters)
      Sets the maximum number of characters of text that the parser extracts from the whole document. The count includes the spaces and line breaks that PDFBox adds between words, lines and pages. If the text of a document has more characters, or if PDFBox reads more characters from a single page (counted as for maxCharactersPerPage(Integer)), ApachePdfBoxDocumentParser.parse(InputStream) throws a RuntimeException. So this limit also bounds the memory needed for one page when the limit per page is turned off.
      Parameters:
      maxCharacters - the maximum number of characters, a positive number, or -1 for no limit; null means the default, 10,000,000
      Returns:
      this builder
      Since:
      1.25.0
    • maxCharactersPerPage

      public ApachePdfBoxDocumentParser.Builder maxCharactersPerPage(@Nullable Integer maxCharactersPerPage)
      Sets the maximum number of characters that the parser reads from a single page. The count is the number of characters of the page's text as PDFBox reads it, before it adds spaces and line breaks. Every character drawn on the page counts, also when it is drawn more than once at the same position. If a page contains more characters, ApachePdfBoxDocumentParser.parse(InputStream) throws a RuntimeException.

      PDFBox keeps every character of a page in memory until the whole page is processed, so this limit bounds the memory needed for one page. A page of dense text usually contains a few thousand characters.

      Parameters:
      maxCharactersPerPage - the maximum number of characters per page, a positive number, or -1 for no limit; null means the default, 100,000
      Returns:
      this builder
      Since:
      1.25.0
    • build

      Creates the parser.
      Returns:
      a new ApachePdfBoxDocumentParser
      Throws:
      IllegalArgumentException - if maxCharacters(Integer) or maxCharactersPerPage(Integer) is not a positive number or -1
      Since:
      1.25.0