RSS

Linux Bash script for combining scanned PDF files into a book

09 Apr

#!/bin/bash

# Script Name: eBookPDFCombine.sh

# to combine separate scanned PDF files into a single PDF book

let numfiles=0

for f in SCN*.pdf

do

numfiles=$(( numfiles + 1 ))

done

numodds=$(( numfiles / 2 ))

numevens=$(( numodds ))

echo $numodds

echo $numevens

rm oddlist.txt

for i in `seq 1 $numodds`do

j=`printf “%03d” $i`

echo “SCN_0″$j”.pdf” >>oddlist.txt

done

oddfiles=`cat oddlist.txt`

echo $oddfilespdftk $oddfiles cat output op.pdf

rm evenlist.txt

for i in `seq $(( numodds+1)) $numfiles`do

j=`printf “%03d” $i`

echo “SCN_0″$j”.pdf” >>evenlist.txt

done

evenfiles=`cat evenlist.txt`

echo $evenfiles

pdftk $evenfiles cat output epback.pdf

pdftk epback.pdf cat end-1 output ep.pdf

# rotate all odd pages to the east, rotate all even pages to the west

pdftk op.pdf cat 1-endE output rotatedodd.pdf

pdftk ep.pdf cat 1-endW output rotatedeven.pdf

pdftk rotatedodd.pdf burst output Burst%04d_A.pdf

pdftk rotatedeven.pdf burst output Burst%04d_B.pdf

pdftk Burst*.pdf cat output allpages.pdfrm Burst*.pdf

Advertisements
 
Leave a comment

Posted by on April 9, 2011 in Bash scripts, eBooks, Scripts and macros

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: