Skip to main content
This guide provides a quick overview for getting started with PDFMiner document loader. For detailed documentation of all PDFMinerLoader features and configurations head to the API reference.

概述

集成详情


加载器特性

设置

凭证

No credentials are required to use PDFMinerLoader If you want to get automated best in-class tracing of your model calls you can also set your LangSmith API key by uncommenting below:

安装

安装 langchain-community and pdfminer

初始化

现在我们可以实例化模型对象并加载文档:

加载

惰性加载

metadata 属性至少包含以下键:
  • source
  • page (if in mode page)
  • total_page
  • creationdate
  • creator
  • producer
额外的元数据因解析器而异。 这些信息可能很有用(例如用于分类你的 PDF)。

Splitting mode & custom pages delimiter

加载 PDF 文件时,你可以用两种不同的方式分割它:
  • By page
  • As a single text flow
默认情况下,PDFMinerLoader will split the PDF by page.

Extract the PDF by page. each page is extracted as a langchain document object

In this mode the pdf is split by pages and the resulting Documents metadata contains the page number. But in some cases we could want to process the pdf as a single text flow (so we don’t cut some paragraphs in half). In this case you can use the single mode :

Extract the whole PDF as a single langchain document object

Logically, in this mode, the ‘page_number’ metadata disappears. Here’s how to clearly identify where pages end in the text flow :

Add a custom pages_delimiter to identify where are ends of pages in single mode

This could simply be \n, or \f to clearly indicate a page change, or <!— PAGE BREAK —> for seamless injection in a Markdown viewer without a visual effect.

Extract images from the PDF

你可以使用三种不同的解决方案从 PDF 中提取图像:
  • rapidOCR (lightweight Optical Character Recognition tool)
  • Tesseract (OCR tool with high precision)
  • Multimodal language model
You can tune these functions to choose the output format of the extracted images among html, markdown or text The result is inserted between the last and the second-to-last paragraphs of text of the page.

Extract images from the PDF with rapidOCR

请注意,RapidOCR 设计用于处理中文和英文,不支持其他语言。

Extract images from the PDF with tesseract

Extract images from the PDF with multimodal model

Working with files

许多文档加载器涉及文件解析。这类加载器之间的差异通常在于文件的解析方式,而不是文件的加载方式。 For example, you can use open to read the binary content of either a PDF or a markdown file, but you need different parsing logic to convert that binary data into text. As a result, it can be helpful to decouple the parsing logic from the loading logic, which makes it easier to reuse a given parser regardless of how the data was loaded. 你可以使用此策略用相同的解析参数分析不同的文件。 可以处理来自云存储的文件。

Using PDFMiner to generate HTML text

This can be helpful for chunking texts semantically into sections as the output html content can be parsed via BeautifulSoup to get more structured and rich information about font size, page numbers, PDF headers/footers, etc.

API 参考

For detailed documentation of all PDFMinerLoader features and configurations head to the API reference