Make a PDF from a series of screenshots

bash
Published

January 12, 2024

You might need to digitize some web content by taking screenshots and then bundling them up in a PDF.

Here I am using Linux from the command line, leveraging convert from Imagemagick and pdftk.

Screenshots are usually in png format, we first want to compress them by turning them into PDF:

for f in *.png
do
    convert "$f" "$f".jpg
done

next we want to convert to PDF, but we need to set the right page size. 1224x792 is the size of 2 sheets in letter format in portrait orientation side by side:

for f in *.jpg
do
    convert "$f" -density 72 -page 1224x792  "${f// /_}".pdf
done

Finally we can concatenate the pdf page to a single document:

pdftk *.pdf cat output document.pdf