Skip to content

Instantly share code, notes, and snippets.

@mitchazj
Last active March 26, 2019 00:31
Show Gist options
  • Save mitchazj/9cc34c5e2b040725362557f5143479a4 to your computer and use it in GitHub Desktop.
Save mitchazj/9cc34c5e2b040725362557f5143479a4 to your computer and use it in GitHub Desktop.
Rotate PDF's (eg, when lecturers constantly upload PDF's that are orientated incorrectly)

Start with installing pdftk (Debian)

sudo apt install pdftk

For Ubuntu 18.04, use the pdftk image from the snap store

sudo snap install pdftk

For Ubuntu 18.04 on WSL, install pdftk from this PPA:

sudo add-apt-repository ppa:malteworld/ppa
sudo apt update
sudo apt install pdftk

Then rotate all PDF's in the current directory

for file in *.pdf; do pdftk "$file" cat 1-endeast output "${file%.pdf}-rotated.pdf"; done

Replace 1-endeast with 1-endwest to rotate in the opposite direction.

Lastly, if you're happy with results, remove un-rotated pdfs

ls | grep -v rotated.pdf | tr "\n" "\0" | xargs -0 rm

and rename back to original filenames

sudo apt install rename
rename 's/-rotated\.pdf$/\.pdf/' *.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment