All posts

PDF to text via CLI

Extract TXT, Markdown, or HTML with OpenDataLoader, then optionally convert HTML to DOCX with soffice.

Open online converter

Packages to install

The engine is a Java CLI plus a JRE 11+. For DOCX you also need LibreOffice Writer. A wrapper named opendataloader-pdf is optional.

default-jre-headless
libreoffice-writer-nogui
fonts-liberation
apt install
sudo apt-get update
sudo apt-get install -y default-jre-headless libreoffice-writer-nogui fonts-liberation

How to run the command

opendataloader-pdf document.pdf -o . -f html --image-output off writes document.html. -f text writes document.txt, -f markdown writes document.md. For Word: convert the HTML with soffice --headless --convert-to docx document.html.

opendataloader-pdf
opendataloader-pdf document.pdf -o . -f html --image-output off

Dockerfile example

Build a minimal Ubuntu image with the required packages and run the conversion inside the container.

Dockerfile
FROM ubuntu:24.04

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        default-jre-headless \
        libreoffice-writer-nogui \
        fonts-liberation && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /work
docker build && docker run
docker build -t pdf-to-text .
docker run --rm -v "$PWD:/work" -w /work pdf-to-text \
  opendataloader-pdf document.pdf -o . -f html --image-output off

Example commands

Run these locally after installing the packages, or inside the container from the Dockerfile.

Example 1
opendataloader-pdf document.pdf -o . -f html --image-output off
Example 2
opendataloader-pdf document.pdf -o . -f text --image-output off
Example 3
java -jar opendataloader-pdf-cli.jar document.pdf -o . -f markdown --image-output off
Example 4
opendataloader-pdf document.pdf -o ./output -f html --image-output off && soffice --headless --convert-to docx --outdir ./output document.html