Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a6d78e9db4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 33 lines (27 sloc) 0.864 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/bin/bash
#
# pdfdir-copy http://github.com/bronson/pdfdir
# Scott Bronson
# 16 May 2009
#
# usage: pdfdir-copy src-dir destination-dir
#
# Uses ghostscript to re-encode an entire directory hierarchy of PDF files.
# This is the best way to remove encryption and recompress but it does take
# considerable CPU time.
#
# TODO: We don't bomb out on empty files. We probably should.
# TODO: We show ugly ghostscript output and no progress info. Ugh.

srcdir="$1"
dstdir="$2"

if [ -z "$srcdir" ] || [ -z "$dstdir" ]; then
echo "usage: $(basename "$0") src-dir destination-dir"
exit
fi

mkdir -p "$dstdir" || exit

find $srcdir -name "*.pdf" | while read i; do
echo "$i"
echo "$i" >> /tmp/errout
mkdir -p "$dstdir/$(dirname "$i")"
gs -sDEVICE=pdfwrite -sOUTPUTFILE="$dstdir/$i" -dBATCH -dNOPAUSE "$i" 2>>/tmp/errout || echo "$i" >> /tmp/badfiles
done

Something went wrong with that request. Please try again.