-
Notifications
You must be signed in to change notification settings - Fork 3
/
pdf_downsample.sh
43 lines (33 loc) · 1.07 KB
/
pdf_downsample.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
#!/bin/bash
#
# Script for converting PDF documents. It tries to get rid of active content
# as well as potential exploits in images without substantial loss of quality.
#
set -e
DPI=72
if [[ $# -lt 1 ]]; then
echo "USAGE $0 <filename1.pdf> [filename2.pdf] ..."
exit 0
fi
for file in "$@"; do
if [[ ! -r ${file} ]]; then
echo "File ${file} is not readable."
exit -1
fi
echo "[+] Creating downsampled PDF for ${file} ..."
gs -dBATCH -dNOPAUSE -dQUIET -dSAFER \
-sDEVICE=pdfwrite \
-sOutputFile=output.pdf \
-dDownsampleColorImages=true \
-dColorImageResolution=150 \
-dDownsampleGrayImages=true \
-dColorImageDownsampleThreshold=1 \
-dGrayImageDownsampleThreshold=1 \
-dColorImageDownsampleType=/Bicubic \
-dGrayImageDownsampleType=/Bicubic \
-dColorImageResolution=${DPI} \
-dGrayImageResolution=${DPI} \
-dMonoImageResolution=100 ${file}
echo "[+] Moving old file ${file} to old_${file}"
mv ${file} old_${file} && mv output.pdf ${file}
done