-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshrinkpdf.sh
executable file
·51 lines (46 loc) · 1.37 KB
/
shrinkpdf.sh
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
51
#!/bin/bash -x
# shrinkpdf: an utility to make pdf smaller
#
# usage: `shrinkpdf mydoc.pdf` => `mydoc_small.pdf`
# if result is still too large, tweak the parameters below and try again
#### CONFIG
# QUALITY: a generic assessment of target quality
# values: /screen -> /ebook -> /printer -> /prepress
QUALITY=/ebook
# IMGRES, FONTRES: resolution of image and fonts
# lower the first in image-heavy docs (e.g. scans), the second in text-heavy
IMGRES=200
FONTRES=1200
# SAMPLE: sampling method, don't touch unless a run takes too much
SAMPLE=/Bicubic
####
INPUT_NAME="$1"
OUTPUT_NAME="${INPUT_NAME%.*}_small.pdf"
gs -q -dNOPAUSE -dBATCH -dSAFER \
-r${FONTRES} \
-dColorImageDownsampleType=${SAMPLE} \
-dColorImageResolution=${IMGRES} \
-dGrayImageDownsampleType=${SAMPLE} \
-dGrayImageResolution=${IMGRES} \
-dMonoImageDownsampleType=${SAMPLE} \
-dMonoImageResolution=${IMGRES} \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=${QUALITY} \
-dEmbedAllFonts=true \
-dSubsetFonts=true \
-sOutputFile="$OUTPUT_NAME" \
"$INPUT_NAME"
# IF EVERYTHING ELSE FAILS, check these out:
#
# convert -units PixelsPerInch myPic.pdf -density 300 fileout.pdf
#
# gs \
# -o out300.png \
# -sDEVICE=pngalpha \
# -r300 \
# input.pdf
#
# full options: http://milan.kupcevic.net/ghostscript-ps-pdf/