Skip to content

Instantly share code, notes, and snippets.

@knee-cola
Created August 19, 2024 12:37
Show Gist options
  • Save knee-cola/d29924031313afb5dee099d96ce83e23 to your computer and use it in GitHub Desktop.
Save knee-cola/d29924031313afb5dee099d96ce83e23 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Merges multiple PDF files into a single PDF file
#
# pdfmerge.sh [input-1.pdf] [input-2.pdf] [output.pdf]
#
# Example: pdfmerge.sh input-1.pdf input-2.pdf output.pdf
#
# written by: Knee-cola
#
# The trick: ghostscript (gs) will do PDF merging for you, it's just not
# obvious and the required defines are not listed in the manual page.
if [ $# -lt 3 ]
then
echo "Usage: pdfmerge.sh input-1.pdf input-2.pdf output.pdf"
exit 1
fi
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE="$3" -dBATCH "$1" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment