Last active
February 1, 2024 17:01
-
-
Save stefanschmidt/5248592 to your computer and use it in GitHub Desktop.
Remove all annotations from a PDF document
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
pdftk original.pdf output uncompressed.pdf uncompress | |
LANG=C sed -n '/^\/Annots/!p' uncompressed.pdf > stripped.pdf | |
pdftk stripped.pdf output final.pdf compress |
Thank you! It is cool!
Be aware that pdftk requires gcj, which was deprecated in 2017. This is old software that needs to be updated.
Just for convenience for anyone finding this via google like me: This is the code to remove all annotations from all pdfs in a directory.
# these are needed on Mac
export LC_CTYPE=C
export LANG=C
# cd /directory/with/pdfs/
for file in *.pdf
do
outname=`sed -e "s/\.pdf$/_.pdf/"<<<"$file"`
pdftk $file output - uncompress | sed '/^\/Annots/d' | pdftk - output $outname compress
echo "$file: done"
done
Is it possible to reduce the opacity?
this leave me with a PDF with a broken xref table :(
pdfcpu annotations remove my.pdf
works reasonably well :)
https://pdfcpu.io/annot/annot
Still works!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A faster (in-memory) way is to use a shell pipeline: