-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf2gray
executable file
·40 lines (38 loc) · 976 Bytes
/
pdf2gray
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
#!/bin/bash
# Downscale colour PDF to grayscale.
# pdf2gray file1.pdf [file2.pdf] [file3.pdf] ... [filen.pdf]
#
# June 2019. yaswant.pradhan
# -----------------------------------------------------------------------------
infile=${1?:"Missing pdf file(s)"}
status=0
errfile=()
for infile in "$@"; do
if [ ! -f "$infile" ]; then
echo "$infile: No such file"
errfile+=("$infile")
((status++))
continue
fi
outfile="${infile%.*}-gray.pdf"
printf "%s -> %s\n" "$infile" "$outfile"
# convert to ebook format
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-dPDFSETTINGS=/ebook \
-dCompressFonts=true \
-dNOPAUSE \
-dQUIET \
-dBATCH \
-dDetectDuplicateImages \
-sOutputFile="$outfile" \
"$infile"
done
# report any error
if [[ "$status" -gt 0 ]]; then
printf "\nUnable to apply conversion to the following file(s):\n"
printf "%s\n" "${errfile[@]}" | nl
fi