Skip to content

Instantly share code, notes, and snippets.

@rcmachado
Created April 24, 2012 21:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcmachado/2484098 to your computer and use it in GitHub Desktop.
Save rcmachado/2484098 to your computer and use it in GitHub Desktop.
Split (extract) pdf pages from larger document
#!/bin/bash
# Usage ./pdfsplitr.sh inputfile.pdf outputfile.pdf pagenumber
# Example: ./pdfsplitr.sh myfile.pdf myotherfile.pdf 2
# http://viktorpetersson.com/2010/10/22/how-to-split-a-pdf-files-on-mac-and-linuxunix/
GS=$(which gs)
# Make sure Ghostscript is installed
if [[ $GS = "" ]]
then
echo “Ghostscript is not installed”
exit
fi
if [[ "$4" = "" ]]
then
LASTPAGE=$3
else
LASTPAGE=$4
fi
# Run the actual conversion.
$GS -sDEVICE=pdfwrite -q -dNOPAUSE -dBATCH -sOutputFile=$2 -dFirstPage=$3 -dLastPage=$LASTPAGE $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment