Wednesday 13 October 2010

Extracting pages from pdf files

Found somewhere on the www while searching for a tool to extract pages from a pdf document using the command-line. Since gs (ghostscript) is installed almost on all unix type system, this routine is portable:


#!/bin/bash
if [ $# -lt 3 -o $# -gt 4 ]; then
echo $usage
else
if [ $# == 3 ]; then
outfile=${3%.pdf}_p${1}-p${2}.pdf
else
outfile=${4}
fi
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage=${1} \
-dLastPage=${2} \
-sOutputFile=${outfile} \
${3}
fi


On the command-line simple type:
pdfpextr firstpage lastpage inputfile [ouputfile]

No comments:

Post a Comment