All posts
Merge PDF via CLI
Concatenate several PDFs into one file with Ghostscript.
Open online converterPackages to install
ghostscript is enough. File order at the end of the command becomes page order in the result.
ghostscript
sudo apt-get update
sudo apt-get install -y ghostscriptHow to run the command
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=merged.pdf a.pdf b.pdf. Add as many input PDFs as you need after OutputFile.
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=merged.pdf a.pdf b.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 merge-pdf .
docker run --rm -v "$PWD:/work" -w /work merge-pdf \
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=merged.pdf a.pdf b.pdfExample commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=merged.pdf a.pdf b.pdfgs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=merged.pdf part1.pdf part2.pdf part3.pdf