PDFtoMD
AI WorkflowsDeepSeekOCRPDF

DeepSeek OCR Tutorial: Convert PDF to Markdown Locally or via API

DeepSeek OCR turns PDFs into clean Markdown with tables and equations intact, running locally through Ollama or as a hosted API. A hands on tutorial with setup, working code, and how it compares to Mistral OCR and Marker.

8 min readBy Rafael Abellan

DeepSeek OCR is a vision language model built to read documents the way a person does: it looks at the page, understands the layout, and writes out the content as clean Markdown. Instead of pulling loose characters from a PDF and hoping the structure survives, it reasons about headings, columns, tables, and equations, then hands you text that is ready for an LLM or a notes app. The best part is that you can run it two ways. You can host it yourself and keep every page on your own machine, or you can call a hosted endpoint and skip the setup entirely.

This tutorial walks through both paths. You will see how to run DeepSeek OCR locally through Ollama, how to call it as an API, what the output actually looks like, and how it compares to alternatives like Mistral OCR and Marker. By the end you will know which approach fits your project and how to get clean Markdown out of even a messy scanned PDF.

What DeepSeek OCR Actually Does

Traditional OCR tools were built to answer one question: what characters are on this page? They are good at that and bad at almost everything else. They do not know that a row of numbers is a table, that a block of italic text is a caption, or that two columns should be read top to bottom before moving right. You get a wall of text with the structure stripped out.

DeepSeek OCR belongs to a newer class of tools. It is a multimodal model, which means it takes an image of the page as input and generates text as output, and it has been trained specifically to produce Markdown. So it does not just transcribe. It reconstructs. Headings come back as ## lines, lists come back as bullet points, tables come back as pipe-delimited Markdown tables, and math comes back as LaTeX between dollar signs. For anyone feeding documents into an AI pipeline, that structure is the whole point.

The trade-off is that it is heavier than a classic OCR engine. It wants a GPU to run comfortably, and a full document takes longer to process than a simple text extraction would. For scanned pages, complex layouts, and anything with tables or equations, that cost buys you output you would otherwise spend an hour cleaning by hand.

When to Choose DeepSeek OCR

DeepSeek OCR is worth reaching for when the document is genuinely hard to read. Consider it in these cases:

  • Scanned or photographed PDFs: Pages that are images, not selectable text, where a plain extractor returns nothing useful.
  • Tables and financial data: Statements, spec sheets, and reports where the grid has to stay intact.
  • Equations and scientific papers: Documents where losing the math means losing the meaning.
  • Multi-column layouts: Academic papers, magazines, and forms where reading order is not obvious.
  • Privacy-sensitive files: Contracts or records that cannot leave your network, where the local option matters.

If your PDF is already clean digital text, you do not need a vision model at all. A fast library will extract it in a fraction of a second. DeepSeek OCR earns its keep on the documents that break simpler tools.

Option A: Run DeepSeek OCR Locally with Ollama

Running the model yourself keeps every page on your own hardware. Nothing is uploaded, which is exactly what you want for legal, medical, or internal documents. Ollama is the simplest way to get there because it handles the model download and serving for you.

Step 1: Install Ollama

Ollama runs on macOS, Linux, and Windows. On macOS and Linux you can install it with a single command:

curl -fsSL https://ollama.com/install.sh | sh

On Windows, download the installer from the Ollama website and run it. Once installed, Ollama runs a local server in the background that listens on port 11434.

Step 2: Pull the model

Download the DeepSeek OCR model to your machine. The first pull fetches several gigabytes, so give it a moment:

ollama pull deepseek-ocr

A GPU with a decent amount of memory makes this pleasant. It will run on CPU, but expect each page to take noticeably longer. If you are on a laptop without a dedicated GPU, the hosted option in the next section will feel much faster.

Step 3: Convert a page to Markdown

Ollama works on images, so the flow is to render each PDF page to a PNG, then send it to the model with a prompt asking for Markdown. Here is a compact Python script that does exactly that using pdf2image and the Ollama Python client:

import ollama
from pdf2image import convert_from_path

pages = convert_from_path("report.pdf", dpi=200)

markdown_parts = []
for i, page in enumerate(pages):
    image_path = f"page_{i}.png"
    page.save(image_path, "PNG")

    response = ollama.chat(
        model="deepseek-ocr",
        messages=[{
            "role": "user",
            "content": "Convert this page to clean Markdown. "
                       "Preserve headings, tables, and equations.",
            "images": [image_path],
        }],
    )
    markdown_parts.append(response["message"]["content"])

with open("report.md", "w") as f:
    f.write("\n\n".join(markdown_parts))

print("Saved report.md")

Run it, and you get a single Markdown file assembled from every page. The dpi=200 setting is a good default. Push it to 300 for dense or low-quality scans where small text needs more detail, at the cost of slower processing.

That is the whole local pipeline: install Ollama, pull the model, render pages, prompt for Markdown. No page leaves your machine, and you can batch a whole folder by wrapping the script in a loop.

No GPU to spare? Convert your PDF to clean Markdown in seconds, free, with no setup required.

Option B: Call DeepSeek OCR as a Hosted API

Local hosting is great until you hit its costs: the download, the GPU, the maintenance. If you would rather send a file and get Markdown back, a hosted endpoint removes all of that. Several providers serve DeepSeek OCR through an OpenAI-compatible chat API, so the request looks familiar if you have used any modern LLM.

The pattern is the same as the local flow, except the model runs on someone else's hardware. You pass a base64-encoded image and ask for Markdown:

import base64
from openai import OpenAI

client = OpenAI(
    base_url="https://your-provider.example/v1",
    api_key="YOUR_API_KEY",
)

with open("page_0.png", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode()

response = client.chat.completions.create(
    model="deepseek-ocr",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text",
             "text": "Convert this page to clean Markdown."},
            {"type": "image_url",
             "image_url": {"url": "data:image/png;base64," + image_b64}},
        ],
    }],
)

print(response.choices[0].message.content)

Because the interface is OpenAI-compatible, you can point most existing tooling at it by swapping the base_url and model name. That makes it easy to prototype locally with Ollama and switch to a hosted endpoint for production scale without rewriting your code.

The trade-off is privacy. Your pages travel to a third party, so a hosted API is the wrong choice for confidential documents. For public content, research papers, and general batch work, it is the faster and cheaper path because you are not paying for idle GPU time.

What the Output Looks Like

The reason to use a vision model is the quality of the Markdown, so it helps to see what comes back. Given a financial report page with a heading and a small table, DeepSeek OCR produces something like this:

## Q3 Revenue Summary

Revenue grew across all regions, led by strong
performance in the APAC segment.

| Region   | Q2 2026 | Q3 2026 | Change |
|----------|---------|---------|--------|
| Americas | 4.2M    | 4.8M    | +14%   |
| EMEA     | 3.1M    | 3.4M    | +10%   |
| APAC     | 2.0M    | 2.7M    | +35%   |

Total revenue reached $10.9M, up from $9.3M
in the prior quarter.

Notice that the table stays aligned, the heading is preserved, and the surrounding prose is intact. For a scientific paper, equations come back wrapped in LaTeX delimiters so a Markdown renderer or an LLM can interpret them correctly. This is the structured output that makes downstream work, from OCR on scanned PDFs to feeding a chatbot, actually reliable.

DeepSeek OCR vs Mistral OCR vs Marker

DeepSeek OCR is one of several strong options, and the right pick depends on what you value most. Here is how the three compare on the points that usually decide it:

ToolRuns locallyHosted APIBest for
DeepSeek OCRYes (Ollama)Yes (providers)Privacy plus flexibility
Mistral OCRNoYesZero-setup accuracy
MarkerYesVia paid serviceFast local batches

Mistral OCR is API-only and excellent when you want high accuracy with nothing to install. Marker is a fast open-source library tuned for local speed on large batches. DeepSeek OCR sits between them: it gives you the local-privacy option that Mistral lacks and the vision-model reasoning that pure-pipeline tools like Marker do not have. If your deciding factor is keeping documents in house while still getting model-quality structure, DeepSeek OCR is the natural fit.

Making the Output Production-Ready

Even a strong model benefits from a light cleanup pass, especially at scale. A few habits keep your Markdown consistent:

  1. Set a clear prompt: Ask explicitly for Markdown and name what to preserve. A vague prompt gives you vaguer output.
  2. Tune your DPI: Use 200 for clean documents and 300 for faint scans. Higher is not always better because it slows things down for no gain on sharp pages.
  3. Stitch pages carefully: Join pages with blank lines so headings do not run together, and consider stripping repeated headers or footers.
  4. Validate tables: Spot-check a few tables against the source. Vision models are strong here but not perfect on very dense grids.
  5. Cache results: Processing is not free, so store the Markdown once and reuse it instead of re-running the model.

If maintaining a GPU pipeline sounds like more than you signed up for, a hosted converter handles the rendering, prompting, and stitching for you. See the use cases for where clean Markdown pays off, from research libraries to RAG ingestion.

Frequently Asked Questions

Do I need a GPU to run DeepSeek OCR locally?

Not strictly, but you will want one. The model runs on CPU, yet each page takes considerably longer, which adds up fast across a document. A GPU with enough memory turns a slow crawl into a smooth batch. If you do not have one, the hosted API or a ready-made converter is the practical choice.

Is the local option really private?

Yes. When you run through Ollama, the model and your pages stay on your machine, and nothing is sent over the network. That is the main reason to self-host rather than call an API. If you use a hosted endpoint instead, your pages do travel to the provider, so reserve that for non-confidential content.

Does DeepSeek OCR handle equations and tables?

Yes, and that is a core strength. Tables come back as Markdown tables, and math comes back as LaTeX. This is exactly why a vision model beats a plain text extractor on scientific papers and financial reports, where losing the structure would lose the meaning.

How does it compare to just extracting text from the PDF?

Plain extraction is faster and perfectly fine for clean digital PDFs. It falls apart on scans, images, and complex layouts, because there is no selectable text to pull or the reading order gets scrambled. DeepSeek OCR reads the page as an image, so it works where extraction fails.

Can I use it to batch-convert a whole folder?

Yes. Wrap the conversion script in a loop over your files, render each page, prompt for Markdown, and write out one .md file per PDF. For large jobs the hosted API scales more comfortably because you are not limited by a single local GPU.

The Takeaway

DeepSeek OCR gives you something rare: a document model you can run entirely on your own hardware for privacy, or call as a hosted API for convenience, using nearly the same code either way. It reads scanned pages, preserves tables, and keeps equations intact, which is exactly what raw text extraction cannot do. Against Mistral OCR and Marker, its edge is that dual local-and-hosted flexibility.

If you have the hardware and the privacy requirement, run it locally through Ollama. If you just need clean Markdown without maintaining a GPU, a hosted converter gets you there in seconds. Either way, the goal is the same: turn a stubborn PDF into structured Markdown your tools can actually use. You can try that free on pdftomd.cloud with 3 conversions a month and no credit card required.

Rafael Abellan

About the author

Rafael Abellan

Founder, PDFtoMD

Rafael Abellan is the founder of Agência Triva and ships independent side projects in parallel. PDFtoMD came out of a personal frustration: he kept burning through Claude AI's token limit by uploading long PDFs, then losing hours waiting for the cap to reset. He built the tool to fix his own workflow, and now uses it every day.

Ready to convert your PDFs to Markdown?

Free account · 3 conversions/month · No credit card required