Convert PDF and Word files to text locally with Docling

Docling turns PDF and Office files into structured Markdown on your own machine, which is the usual first step before documents go into an AI search. This tutorial converts one file and then a whole folder.

Niklas Schult4 min read

Isometric view of a compact AI computer in an office

What you will have at the end and what you need

At the end you will have a folder of Markdown files, one for each PDF or DOCX document in a source folder. Markdown keeps headings, tables and reading order in plain text, which suits indexing for an AI search. The Docling README lists local execution for sensitive data and air-gapped environments among the features.

You need Python 3.10 or higher, because support for Python 3.9 was dropped in docling version 2.70.0. The README states that Docling runs on macOS, Linux and Windows, on both x86_64 and arm64. A test folder with a few PDF and Word files helps, ideally without confidential content for the first run.

Install Docling and convert the first file

Docling is published as a Python package. The following command installs it, ideally inside a virtual environment, and the README points to a separate page with detailed installation instructions.

Shell
pip install docling

The command line tool takes a path or a URL. The next command converts a local contract PDF. According to the README, it writes a Markdown file with the structured content into the current directory.

Shell
docling vertrag.pdf

Once this works, you know that the installation is complete and that your machine can read the file format. Only then is it worth writing a script, because any later problem can be traced to the script rather than to the setup.

Process a whole folder with a Python script

The README recommends the Python interface for real use. The script below creates a converter once and walks through the folder named dokumente. It converts every PDF and DOCX file and writes the Markdown export into a folder named text, using the original file name.

Python
from pathlib import Path
from docling.document_converter import DocumentConverter

converter = DocumentConverter()
out = Path("text")
out.mkdir(exist_ok=True)

for pfad in Path("dokumente").iterdir():
    if pfad.suffix.lower() in (".pdf", ".docx"):
        result = converter.convert(str(pfad))
        md = result.document.export_to_markdown()
        (out / (pfad.stem + ".md")).write_text(md, encoding="utf-8")

Other formats from the README, such as PPTX, XLSX or HTML, need their suffixes added to the filter. The documentation excerpt does not show how the converter handles errors in single files, so a production script needs its own error handling.

The converter object is created once outside the loop, so the setup cost is paid a single time and not for every file. The README also lists export formats beyond Markdown, including HTML and lossless JSON, which you may prefer if later steps need the full document structure.

Check that the conversion works

Open a few of the generated files in the text folder and compare them with the originals. Look at headings, the order of paragraphs and especially tables, since the README names page layout, reading order and table structure as areas of its PDF understanding. Check that the number of Markdown files matches the number of PDF and DOCX files in the source folder.

Documents with unusual layouts deserve a closer look. A sample of the most complex files in your archive tells you more than a hundred simple letters. Keep a short note of which files failed or looked wrong, so that you can repeat the same test after every update of the package.

Typical pitfalls according to the documentation

The README mentions few pitfalls, and they are practical. Python 3.9 no longer works with current versions, so older servers may need a newer interpreter. Scanned PDFs and images depend on the OCR support the README lists, and the excerpt does not describe how to configure it.

Model licences are a further point. The Docling code is under the MIT licence, but the README asks users to read the licences of individual models in the original packages. The README also mentions visual language models such as GraniteDocling, started with the option --vlm-model granite_docling, which you choose separately from the default run.

Where this fits in a company

Conversion is one stage of a larger pipeline. Someone has to own the script, update the package, decide which folders are read and store the Markdown files with the same access rights as the originals. Because the README describes local execution, the step can run on an internal server, and the data protection officer or the Betriebsrat (works council) can review the setup like any other internal tool. For general questions see GDPR and AI at work and local AI.

A converter alone gives you no search, citations or permissions. souveraen.ai is an AI platform for company knowledge that connects sources such as file servers and SharePoint read-only with existing permissions. It can run hosted in Germany or on-premise. More on that appears under knowledge management software and on-premise operation.

Sources

More articles

All articles

How safe are AI API routes via resellers and routers?

Security firm Dragos sent about two million requests with fake credentials to AI providers and found compromised services and resellers reading customer prompts. Companies that use AI through third parties need to know who sits on the path of their data.

Data protection4 min

Run Text Generation Inference with Docker on Your Server

Text Generation Inference (TGI) serves open language models from a single Docker container on your own hardware. This tutorial starts it, sends requests over HTTP and keeps prompts inside your network.

Tutorial4 min

Cloud outage liability: who answers when Microsoft fails

On 12 November 2026 a software fault took Exchange Online and Outlook offline for about 36 hours. A legal analysis published shortly afterwards argues that responsibility for such outages often lies with the operator rather than the provider.

Regulation4 min

Test it with your own documents.

Free for 3 days, then from €24.90 per user per month. Cancellable monthly.

Free for 3 days, then from €24.90 per user per month.Free for 3 days
Try free for 3 days