Created
October 20, 2021 19:42
-
-
Save dtxe/b0073f40f346620fbeccdc0f403cf521 to your computer and use it in GitHub Desktop.
Use ghostscript to repair all PDFs within a ZIP file (of student submissions from UofT Quercus)
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 -x | |
# fixQpdf.sh [zip file] [output folder] | |
BASEDIR=$HOME | |
TEMPDIR=$(uuidgen) | |
mkdir $BASEDIR/$TEMPDIR | |
mkdir $BASEDIR/$2 | |
unzip $1 "*.pdf" -d $BASEDIR/$TEMPDIR | |
# repackage all PDF files | |
find $BASEDIR/$TEMPDIR -iname "*.pdf" -printf "%f\n" | xargs -d "\n" -I @ -P 24 gs -o \"$BASEDIR/$2/@\" -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress \"$BASEDIR/$TEMPDIR/@\" | |
basezip=$(basename $1 .zip) | |
zip -j $basezip.fixed.zip $BASEDIR/$2/* | |
rm -r $BASEDIR/$TEMPDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment