Add more qpdf options for smaller file sizes

This commit is contained in:
Dan Church 2021-06-29 13:30:42 -05:00
parent a6a00d300c
commit 38411917a9
Signed by: h3xx
GPG Key ID: EA2BF379CD2CDBD0
1 changed files with 16 additions and 3 deletions

19
optipdf
View File

@ -2,6 +2,7 @@
# vi: et sts=4 sw=4 ts=4
PRESERVE_TIMESTAMP=0
LOSSY=0
KEEP_BACKUP_SUFFIX=.old-unoptimized
TEMP_FILES=()
@ -126,6 +127,20 @@ use_smaller() {
TEMP=$(mktemp -t "${0##*/}.XXXXXX")
TEMP_FILES+=("$TEMP")
QPDF_ARGS=(
--compression-level=9
--deterministic-id
--object-streams=generate
--recompress-flate
--stream-data=compress
)
if [[ $LOSSY -ne 0 ]]; then
QPDF_ARGS+=(
--optimize-images
)
fi
ERRORS=0
FREED_TOTAL=0
for FILE; do
@ -133,9 +148,7 @@ for FILE; do
BEGIN_FILESIZE=$(file_size "$FILE")
if
qpdf \
--recompress-flate \
--stream-data=compress \
qpdf "${QPDF_ARGS[@]}" \
-- \
"$FILE" "$TEMP" &&
use_smaller "$FILE" "$TEMP"; then