Skip to content

Instantly share code, notes, and snippets.

@eplt
Last active October 6, 2021 03:22
Show Gist options
  • Save eplt/3046dd9b64ad8fa134e502bd8939e23f to your computer and use it in GitHub Desktop.
Save eplt/3046dd9b64ad8fa134e502bd8939e23f to your computer and use it in GitHub Desktop.
Extract and Combine First Page of each PDF in folder - OS X, requires GS or PDFTK
#!/bin/bash
#
echo "Start Script"
rm combined.pdf
for file in *.pdf ; do pdftk "$file" cat 1 output "${file%.pdf}-page1.pdf" ; done
pdftk *-page1.pdf cat output combined.pdf
#for file in *.pdf ; do gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="${file%.pdf}-page1.pdf" -dFirstPage=1 -dLastPage=1 "$file" ; done
#gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE#pdfwrite -sOutputFile#"combined.pdf" *-page1.pdf
rm *-page1.pdf
echo "End Script"
@eplt
Copy link
Author

eplt commented Sep 7, 2016

You might need to install Ghostscript or PDFTK

Check out http://stackoverflow.com/questions/32505951/pdftk-server-on-os-x-10-11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment