blob: 41f31f0d2376e0019ca00e0c58ce246d73c2c1a8 (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/bin/bash
INPUTPDF="$1"
if [ -z $1 ]; then
echo "Usage: pdfshrink inputfile.pdf [quality [outputfile]]"
exit 1
fi
# values for 'quality' argument:
#
# 'prepress' is highest quality,
# 'ebook' is only 150 dpi
# 'screen' is 72dpi - looks very poor
# 'printer' and 'default' are good compromises
if [ ! -f "$INPUTPDF" ]; then
echo "file $INPUTPDF not found"
exit 1
fi
quality=${2-default}
if [ $quality = 'default' ]; then
suffix="shrunk"
else
suffix=$quality
fi
OUTPUTPDF="${3-${1%.pdf}-${suffix}}"
OUTPUTPDF="${OUTPUTPDF%.pdf}.pdf"
echo "converting $INPUTPDF to $OUTPUTPDF using quality '$quality'"
gs -sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dHaveTransparency=true \
-dFastWebView=true \
-dPrinted=false \
-dPDFSETTINGS=/$quality \
-dEmbedAllFonts=true \
-dSubsetFonts=true \
-dNOPAUSE \
-dQUIET \
-dBATCH \
-sOutputFile="$OUTPUTPDF" \
"$INPUTPDF" 2> /dev/null
chmod 644 "$OUTPUTPDF"
echo "done"
|