# Chat with Your PDFs Locally | PDFluent

Source: https://pdfluent.com/blog/chat-with-your-pdfs-locally/

All posts

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

# Chat with your PDFs locally

pdf python mcp privacy

I am a solo founder. PDFluent is a PDF SDK and editor written in Rust. Local-first, privacy-first. Your documents stay on your machine. No account.

Two ways to chat with a PDF here. One is the MCP server, which drops into a client you already use. The other is a short script that talks to a local model.

## The MCP server

pdfluent-mcp 0.3.0 is an MCP server for Claude Desktop, Claude Code, Cursor, VS Code, Codex and other MCP clients. It gives the client nine tools: `extract_markdown`, `extract_text`, `extract_tables`, `extract_blocks`, `get_metadata`, `search`, `list_form_fields`, `fill_form` and `vision_advice`. It reads a local PDF as markdown, plain text, tables or positioned blocks. It looks up metadata, searches the text, lists form fields and fills them into a new file. It runs over stdio on your machine and reads and writes only inside the directories you allow, so your documents are not uploaded. It needs Python 3.10 or later and uv. One command registers it in Claude Desktop, Claude Code, Cursor and Codex: `uvx pdfluent-mcp setup --root ~/Documents`. By hand it is `claude mcp add pdfluent -- uvx pdfluent-mcp --root /path/to/documents`, or `pip install pdfluent-mcp` and then `pdfluent-mcp --root ~/Documents`. Tool paths must be absolute. The server keeps your PDF on your machine. Whether the chat itself is local depends on the model you connect. A hosted model still receives the excerpts it is shown.

## A script against a local model

If you want nothing to leave the machine at all, point the model at a local OpenAI-compatible server such as Ollama and write the loop yourself. Install with `pip install pdfluent==1.5.0`, then run this:

python

```
import json
import re
import sys
import urllib.request

import pdfluent

PDF, QUESTION = sys.argv[1], sys.argv[2]
ENDPOINT = "http://localhost:11434/v1/chat/completions"  # Ollama; any OpenAI-compatible local server works
MODEL = "llama3.1"

doc = pdfluent.open(PDF)
markdown = doc.extract_markdown(quality="fast")

# One chunk per heading section keeps tables and lists together.
sections = [s.strip() for s in re.split(r"\n(?=#{1,3} )", markdown) if s.strip()]

def score(section: str) -> int:
    words = set(re.findall(r"\w+", QUESTION.lower()))
    return sum(1 for w in re.findall(r"\w+", section.lower()) if w in words)

context = "\n\n".join(sorted(sections, key=score, reverse=True)[:3])

body = {
    "model": MODEL,
    "messages": [
        {"role": "system", "content": "Answer only from the document excerpts. Say so if the answer is not there."},
        {"role": "user", "content": f"Excerpts:\n{context}\n\nQuestion: {QUESTION}"},
    ],
}
request = urllib.request.Request(
    ENDPOINT, json.dumps(body).encode(), {"Content-Type": "application/json"}
)
with urllib.request.urlopen(request) as response:
    print(json.load(response)["choices"][0]["message"]["content"])
```

Run it with `python chat_local.py /absolute/path/report.pdf "What are the rates for the standing band?"`.

The extraction does most of the work. `pdfluent.open(path)` returns a document, and `doc.extract_markdown(quality="fast")` returns it as markdown in reading order: headings as `#`, list items as `-`, tables as pipe tables, and `<!-- page N -->` comments at page changes. The `fast` tier runs without any model download. A small test PDF comes back as `# Safety rules`, three list items, a `<!-- page 1 -->` comment, then a pipe table with Band, Units and Rate columns.

The script splits that markdown on headings, one chunk per section, and keeps the three sections that share the most words with your question. Splitting on headings is the part that matters. A table stays in one piece with the paragraph that explains it, and a list stays under its heading. Cut the text into fixed-size blocks instead and you will eventually hand the model half a table and a stray row.

## What it does not do

The retrieval is crude. It is word overlap, nothing more. If your question uses different words than the document does, it will miss. Swap in embeddings if you need that. The rest of the script does not change.

Scanned PDFs need OCR. The extraction here reads text, not pixels.

The model is yours to pick. A small local model will answer worse than a large one, and nothing here fixes that.

The script was checked end to end against a stand-in HTTP server for the model, not against a real local model. The plumbing works. The answers depend on what you run behind it.

The SDK is AGPL-3.0 or a commercial licence, your choice.

https://pdfluent.com, install with `pip install pdfluent==1.5.0`.

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