-
-
Save stefanschmidt/5248592 to your computer and use it in GitHub Desktop.
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 for sharing this script, it worked perfectly!
Thank you
sed: RE error: illegal byte sequence
hmmm
Works perfectly! Thank you
It works, thank you very much.
I would suggest using LANG=C sed -i '/^\/Annots/d' uncompressed.pdf
to modify the uncompressed.pdf in place.
For those getting the Illegal byte sequence
error, try adding LC_CTYPE=C
at the beginning of the second command as well
e.g. LANG=C LC_CTYPE=C sed -n '/^\/Annots/!p' uncompressed.pdf > stripped.pdf
Thanks!
Thaank you! Worked great 👍
Just be aware that the annotation text (there is any) remains in the file. It's just not visible any more.
Thanks! Here a for loop for cleaning several pdfs:
for file in *.pdf; do pdftk "$file" output un.pdf uncompress; LANG=C sed -n '/^/Annots/!p' un.pdf > str.pdf; pdftk str.pdf output "$file" compress; echo "Done $file"; done;
This did not work for me. I had to remove all "/Type /Annot" commands as well in sed for the yellow annotations to disappear.
A faster (in-memory) way is to use a shell pipeline:
pdftk in.pdf output - uncompress | sed '/^\/Annots/d' | pdftk - output out.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
Sweet! This worked great for me.