Pages

Thursday, April 04, 2013

bash script to extract and join pdf files


Here is a script which will take out the last page from a pdf file and attache it to a template pdf file.

The requirement are ghostscript and xpdf-utils.


#!/bin/bash
for i in `ls *.pdf`
do

pdfinfo -meta $i | grep -i pages
count=$(pdfinfo -meta $i | grep -i pages |cut -d ":" -f2| tr -d " ")
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage=$count -dLastPage=$count \
-sOutputFile=lastpage.$i $i
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-sOutputFile=finished.$i template.pdf lastpage.$i
done
echo "converted files successfully"

No comments:

Post a Comment