#!/bin/bash # # Syntax: pdf_extract_pages [-h] range pdf_file # # Purpose: Use pdftk to extract pages from a pdf file. # Page ranges can be specified as X-Y, X-end, X-Yeven, # X-Yodd, or as "X Y Z" (note the quotes!). # Output is stored in the file pdf_file_pages.pdf # Note: If pdftk is not installed or not available, # pdf_extract_pages_gs can be used instead. # # See also: pdf_extract_pages_gs # Created: Jan 8, 2007 by Bart De Schutter # Last revised: Jan 11, 2011 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: pdf if [ $# -ge 1 -a "$1" = "-h" ]; then sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi if [ $# -ne 2 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires exactly 2 input arguments." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi pdf_file="$2" if [ ! -e "$pdf_file" ]; then echo >&2 echo >&2 "ERROR: File $pdf_file not found." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi pdftk "$2" cat $1 output "${pdf_file%.pdf}_pages.pdf"