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

Overview

Integration details


Loader features

Setup

Credentials

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:

Installation

Install langchain-community and pdfminer.

Initialization

Now we can instantiate our model object and load documents:

Load

Lazy load

The metadata attribute contains at least the following keys:
  • source
  • page (if in mode page)
  • total_page
  • creationdate
  • creator
  • producer
Additional metadata are specific to each parser. These pieces of information can be helpful (to categorize your PDFs for example).

Splitting mode & custom pages delimiter

When loading the PDF file you can split it in two different ways:
  • By page
  • As a single text flow
By default 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

You can extract images from your PDFs with a choice of three different solutions:
  • 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

Be careful, RapidOCR is designed to work with Chinese and English, not other languages.

Extract images from the PDF with tesseract

Extract images from the PDF with multimodal model

Working with files

Many document loaders involve parsing files. The difference between such loaders usually stems from how the file is parsed, rather than how the file is loaded. 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 re-use a given parser regardless of how the data was loaded. You can use this strategy to analyze different files, with the same parsing parameters. It is possible to work with files from cloud storage.

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 reference

For detailed documentation of all PDFMinerLoader features and configurations head to the API reference: python.langchain.com/api_reference/community/document_loaders/langchain_community.document_loaders.pdf.PDFMinerLoader.html

Connect these docs to Claude, VSCode, and more via MCP for real-time answers.