Skip to content

Instantly share code, notes, and snippets.

@dtxe
Created October 20, 2021 19:42
Show Gist options
  • Save dtxe/b0073f40f346620fbeccdc0f403cf521 to your computer and use it in GitHub Desktop.
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)
#!/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