1
0
Fork 0
hsarch/scripts/generate_compressed.sh

40 lines
853 B
Bash
Executable file

#!/usr/bin/bash
set -e
cd "$(dirname "$0")/.."
echo
echo "-> Generating Compressed PDFs"
if ! command -v gs >/dev/null; then
echo "Could not find GhostScript."
echo "Please install it with 'sudo apt install ghostscript'."
exit 1
fi
pdfs=()
get_compressed_path () {
echo "$1" | sed -r 's/(.+)\/([^/]+)\.pdf/\1\/compressed\/\2.pdf/'
}
for file in assets/files/*/pdf/*.pdf; do
compressed="$(get_compressed_path "$file")"
if [ ! -f "$compressed" ]; then
pdfs+=("$file")
fi
done
i=1
n="${#pdfs[@]}"
if [ "$n" == "0" ]; then
echo "(Nothing to do)"
else
for file in "${pdfs[@]}"; do
printf "Compressing PDF $i/$n ($file)... "
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$(get_compressed_path "$file")" "$file"
printf "Done\n"
i=$(( i + 1 ))
done
fi