# Replace PyPDFLoader in LangChain | PDFluent

Source: https://pdfluent.com/blog/replace-pypdfloader-in-langchain/

All posts

Guides November 18, 2026 3 min read by [Jasper de Winter](https://www.linkedin.com/in/jasperdewinter/), Founder, PDFluent

# Replacing PyPDFLoader in LangChain

langchain python rag pdf

I'm a solo founder and I build PDFluent. It's local-first and privacy-first. Documents stay on your machine, no account. That's where the loader comes from.

PyPDFLoader in langchain-community gives you one Document per page of plain text. That works until the page has structure. List bullets arrive as "•" characters and heading marks are gone. langchain-community is being sunset per its own deprecation warning, so standalone packages are worth a look.

Two things matter to me here. The structure of the page survives the read, and the pieces come with metadata you can filter on. That's what I wanted from a loader. Throwing structure away at the read step and guessing it back later is a bad trade. If the marks are in the text, you don't need a second pass to find them.

`langchain-pdfluent` 0.2.0 is on PyPI. It ships `PDFluentLoader` in `langchain_pdfluent`, and it needs the `pdfluent` Python SDK, 1.2.0 or later. Install is `pip install langchain-pdfluent`.

On a small two-page test PDF with a heading, three list items and a table, PyPDFLoader returned 2 docs. The text of the first one read `Safety rules\n• Wear the issued boots on the floor.\n• Keep the gangways`. PDFluentLoader with mode="markdown" returned 2 docs, and the same text read `# Safety rules\n\n- Wear the issued boots on the floor.\n- Keep the gangw`. The markdown marks are still there. I will not claim it is faster or more accurate. The difference shows up in the output and in the metadata.

The swap is two lines.

python

```
from langchain_community.document_loaders import PyPDFLoader
from langchain_pdfluent import PDFluentLoader

before = PyPDFLoader("structured.pdf").load()
after = PDFluentLoader("structured.pdf", mode="markdown").load()

blocks = PDFluentLoader("structured.pdf").load()
for doc in blocks:
    print(doc.metadata["kind"], doc.metadata["page"], repr(doc.page_content[:60]))
```

`before` and `after` are both lists of Documents, so whatever reads them downstream keeps working. The third part of the snippet is blocks mode, which is the default.

In blocks mode you get one Document per block, with a `kind` in the metadata. On the test PDF the kinds were `heading`, `list_item` and `table`. The heading block printed `heading 0 'Safety rules'`. The three list items printed `list_item 0` with their text. The table printed `table 1` with its rows. Each block also carries `page`.

Markdown mode gives one Document per page, rendered as markdown. The metadata keys are `kind`, `page`, `source`, `tables` and `toc_items`.

So which one do you pick? If you're building an index that reads prose, markdown mode keeps the page together and keeps the marks. If you want to route on what a piece of the page is, use blocks mode. Both give you Documents, so you can switch later without touching the rest of the pipeline. The defaults are `mode="blocks"`, `quality="fast"`, `include_furniture=False` and `first_page=0`, so a plain call gives you blocks. You can take a page range with `page_count` or `pages`, cap block size with `max_chars`, and point at table models with `table_model_dir`. There is a `hierarchical` flag too.

On splitting, markdown mode on a 50-page file gave 50 Documents. `RecursiveCharacterTextSplitter(chunk_size=200, chunk_overlap=20)` split them into chunks whose metadata keys are `kind`, `page`, `source`, `tables` and `toc_items`. So the page and the source survive the split, and you can filter on them.

The SDK 1.4.0 also reads CSV, TSV, JSON, XML, RTF, HTML, Markdown, plain text and e-mail (`.eml`) into the same block structure in Python. Every element carries an `element_id` that is the same across separate runs on the same input.

The SDK is AGPL-3.0 or a commercial licence.

https://pdfluent.com and `pip install langchain-pdfluent`

[All posts](https://pdfluent.com/blog/)[RSS feed](https://pdfluent.com/rss.xml)
