-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdfcompress
More file actions
executable file
·33 lines (28 loc) · 790 Bytes
/
pdfcompress
File metadata and controls
executable file
·33 lines (28 loc) · 790 Bytes
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
#!/bin/bash
# pdftk is needed
# Step 1: convert to ps
# Step 2: convert back to pdf
# source: https://pandemoniumillusion.wordpress.com/2008/05/07/compress-a-pdf-with-pdftk/
INPUT="$1"
OUTPUT=""
PS=".ps"
PDF=".pdf"
COMP="_compressed"
TMP="/tmp/$INPUT$PS"
if [[ -z "$2" ]] ; then
read -p "Original File will be overwriten. Append \"$COMP\" (c), continue (Y) or aboard (n) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Y]$ ]] ; then
pdf2ps "$INPUT" "$TMP"
ps2pdf "$TMP" "$INPUT"
elif [[ $REPLY =~ ^[c]$ ]] ; then
pdf2ps "$INPUT" "$TMP"
# TODO add sed args to remove .pdf before _compressed
newname=$(sed -e "s/.pdf//g" <<< $INPUT)$COMP$PDF
ps2pdf "$TMP" "$newname"
fi
else
OUTPUT="$2"
pdf2ps "$INPUT" "$TMP"
ps2pdf "$TMP" "$2"
fi