Created
November 9, 2016 17:05
-
-
Save hogashi/8cbe922cf1bb31eb1639f7e12b1223fd to your computer and use it in GitHub Desktop.
minimize PDF with JPG compressing
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/bash | |
# pdf-unlock-minimize.sh <- base dir is where this script is, you must run this from here | |
# |- pdf/ | |
# | \- 01.pdf, 02.pdf,... <- put PDFs you want to minimize, then run this script | |
# |- dec/ <- decrypted PDFs | |
# |- jpgs/ | |
# | \- 01/ <- compressed JPGs from raw/ | |
# | \- raw/ <- displayed raw JPGs | |
# | \- 02/ | |
# | ... | |
# \- mini/ <- minimized PDFs (you wanted to get) | |
PASSWORD="********" | |
mkdir -p dec mini | |
for i in pdf/*.pdf; do | |
PDFFILE=$(basename ${i}) | |
PDFNUM=${PDFFILE%.pdf} | |
if [ -e mini/${PDFNUM}_mini.pdf ]; then | |
continue | |
fi | |
mkdir -p jpgs/${PDFNUM}/raw | |
qpdf --decrypt --password=${PASSWORD} ${i} dec/${PDFNUM}_dec.pdf | |
convert dec/${PDFNUM}_dec.pdf jpgs/${PDFNUM}/raw/${PDFNUM}-dest.jpg | |
for j in jpgs/${PDFNUM}/raw/${PDFNUM}-dest-*.jpg; do | |
JPGFILE=$(basename ${j}) | |
JPGDIR=$(dirname ${j}) | |
convert -resize 600x -unsharp 2x1.4+0.5+0 -colors 65 -quality 100 -verbose ${JPGDIR}/${JPGFILE} ${JPGDIR%raw}${JPGFILE} | |
done | |
convert ${JPGDIR%raw}*.jpg mini/${PDFNUM}_mini.pdf | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment