-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
pdflat
executable file
·42 lines (34 loc) · 1008 Bytes
/
pdflat
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
#!/bin/bash
[ -z "$1" ] && echo "Please enter a filename. Exiting..."
[ -z "$1" ] && exit 1
dir="$(mktemp -ud | sed 's/tmp\./pdflat./')"
[ -d "${dir}" ] || mkdir "${dir}"
echo
echo -e "\e[1mThis will flatten the following PDFs:\e[0m"
echo
for p in "$@"; do echo "$p"; c=$((c+1)); done
echo
echo -e "\e[1mCount: $c\e[0m"
echo
echo -e "\e[1m\e[32mPress [Enter] to continue... \e[31m[Ctrl+C to cancel]\e[0m"
read
printf "Flattening... "
for a in "$@"; do mv "${a}" "${dir}/${a}"; done
for b in "${dir}/"*".pdf"; do
cc=$((cc+1))
printf "\rFlattening... $cc of $c"
gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -dPreserveAnnots=false -sOutputFile="$(basename "${b}")" "$b"
done
echo ". Done."
echo
echo -e "Originals can be found here: \e[93m${dir}\e[0m"
echo
echo -ne "\e[32mMove ${dir} to \"orig\" folder? [y/N] \e[0m"
read yn
echo
[[ "${yn,,}" == y* ]] && {
[ -d orig ] || mkdir orig
rsync -a "${dir}/" orig/ && rm -r "${dir}"
echo "Moved ${dir} to orig, done."
echo
}