Skip to content

Instantly share code, notes, and snippets.

@jaygooby
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaygooby/78d5642154cd213b6f5b to your computer and use it in GitHub Desktop.
Save jaygooby/78d5642154cd213b6f5b to your computer and use it in GitHub Desktop.
Combine multiple pdfs, potentially with spaces in their name, using pdftk and xargs
#!/bin/bash
#
# Props to http://www.lornajane.net/posts/2011/combining-pdf-files-with-pdftk
# found via http://stackoverflow.com/questions/19122448/bash-escaping-spaces-in-filename-in-variable#comment42365877_19122448
#
# here the sort is used because the pdfs are named something like page 01.pdf page 02.pdf and the -z means the whitespace
# doesn't cause any issues
find ./somepath -name "*.pdf" -print0 | sort -z | xargs -0 -J % pdftk % cat output out.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment