Skip to content

Instantly share code, notes, and snippets.

@lijikun
Last active June 12, 2020 15:25
Show Gist options
  • Save lijikun/7253f64f74133f3eb583d7cb6a0441c6 to your computer and use it in GitHub Desktop.
Save lijikun/7253f64f74133f3eb583d7cb6a0441c6 to your computer and use it in GitHub Desktop.
Creating a PDF file containing the first page of multiple PDFs using Linux command line

Extracting First Pages of Multiple PDFs and Combining Them Into a Single File

Prequisites

  • Linux, bash, qpdf, pdfunite

  • Your source PDF files collected in a directory (e.g. /tmp/source)

  • An empty, temporary folder to collect intermediate files (e.g. /tmp/PDFs)

Commands

cd /tmp/source
mkdir /tmp/PDFs
for x in *.pdf; do qpdf --pages $x 1 -- --empty /tmp/PDFs/$x.pdf; done
pdfunite /tmp/PDFs/* my-target-file.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment