All posts
PDF to images via CLI
Rasterize PDF pages to PNG with Ghostscript.
Open online converterPackages to install
You need ghostscript and the png16m device. -r sets DPI: 150 for previews, 300 for print.
ghostscript
sudo apt-get update
sudo apt-get install -y ghostscriptHow to run the command
gs -sDEVICE=png16m -r150 -sOutputFile=page-%02d.png input.pdf. The %02d pattern writes page-01.png, page-02.png, and so on.
gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -r150 -sOutputFile=page-%02d.png input.pdfDockerfile 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 \
ghostscript && \
rm -rf /var/lib/apt/lists/*
WORKDIR /work
docker build -t pdf-to-images .
docker run --rm -v "$PWD:/work" -w /work pdf-to-images \
gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -r150 -sOutputFile=page-%02d.png input.pdfExample commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -r150 -sOutputFile=page-%02d.png input.pdfgs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -r300 -sOutputFile=page-%03d.png input.pdf