Skip to content

Instantly share code, notes, and snippets.

@majal
Forked from stefanschmidt/remove-annotations.sh
Last active November 12, 2020 20:27
Show Gist options
  • Save majal/ea3b483e3758a5084948a39b09df9b2d to your computer and use it in GitHub Desktop.
Save majal/ea3b483e3758a5084948a39b09df9b2d to your computer and use it in GitHub Desktop.
Remove all annotations from a PDF document
#!/bin/bash
[[ -z "$1" ]] && echo "Please enter a filename. Exiting..."
[[ -z "$1" ]] && exit 1
echo
printf "Stripping annotations from $1... "
pdftk "$1" output "/tmp/$1 - uncompressed.pdf" uncompress
LANG=C sed -n '/^\/Annots/!p' "/tmp/$1 - uncompressed.pdf" > "/tmp/$1 - stripped.pdf"
pdftk "/tmp/$1 - stripped.pdf" output "$1 - No Annotations.pdf" compress
echo "and saved as $1 - No Annotations.pdf. Done. ;-)"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment