All posts
DOC and DOCX to PDF via CLI
Headless LibreOffice (soffice) converts Word DOC and DOCX to PDF.
Open online converterPackages to install
Install libreoffice-writer-nogui and fonts-liberation so the document renders predictably.
libreoffice-writer-nogui
fonts-liberation
sudo apt-get update
sudo apt-get install -y libreoffice-writer-nogui fonts-liberationHow to run the command
soffice --headless --convert-to pdf --outdir . document.docx. The same command works for .doc. On a server, set a private profile with -env:UserInstallation so parallel runs do not clash.
soffice --headless --nologo --nofirststartwizard --norestore --convert-to pdf --outdir . document.docxDockerfile example
Build a minimal Ubuntu image with the required packages and run the conversion inside the container.
FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libreoffice-writer-nogui \
fonts-liberation && \
rm -rf /var/lib/apt/lists/*
WORKDIR /work
docker build -t docx-to-pdf .
docker run --rm -v "$PWD:/work" -w /work docx-to-pdf \
soffice --headless --nologo --nofirststartwizard --norestore --convert-to pdf --outdir . document.docxExample commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
soffice --headless --nologo --nofirststartwizard --norestore --convert-to pdf --outdir . document.docxsoffice -env:UserInstallation=file:///tmp/lo-profile --headless --convert-to pdf --outdir /tmp document.doc