Created
January 23, 2017 11:47
-
-
Save glenux/9054bed8bef8f7b3785ad57fa27a71f3 to your computer and use it in GitHub Desktop.
Script to compress large bitmap PDFs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
INPUT="$1" | |
TMPDIR=`mktemp -d` | |
# TODO: READ ALSO https://gist.github.com/yura/670974 | |
echo "Input file: $INPUT" | |
echo "Converting PDF to images" | |
#convert -density 150 -quality 100 -colors 256 "$INPUT" "$TMPDIR/hires-%03d.png" | |
convert -density 200 -quality 100 -colors 512 "$INPUT" "$TMPDIR/hires-%03d.png" | |
echo "Compressing & merging images to flat PDF" | |
convert -compress jpeg -quality 75 "$TMPDIR/hires-"*.png "$TMPDIR/flat_${INPUT}" | |
echo "done." | |
echo "Compressing PDF" | |
# Compression 1 | |
pdftk "$TMPDIR/flat_${INPUT}" output "$TMPDIR/compress_${INPUT}" compress | |
# LOSSLESS | |
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile="re_${INPUT}" "$TMPDIR/compress_${INPUT}" | |
rm -fr "$TMPDIR" | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment