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

Overview

Integration details


Loader features

Setup

Credentials

No credentials are required to use PyPDFLoader. To enable automated tracing of your model calls, set your LangSmith API key:

Installation

Install langchain-community and pypdf.

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 PyPDFLoader will split the PDF as a single text flow.

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.

API reference

For detailed documentation of all PyPDFLoader features and configurations head to the API reference: python.langchain.com/api_reference/community/document_loaders/langchain_community.document_loaders.pdf.PyPDFLoader.html
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.