strip-pdf-metadata.sh 583 B

12345678910111213141516171819202122232425
  1. inf="$1"
  2. outf="$2"
  3. tag="$1"
  4. pdftk "$inf" dump_data | \
  5. sed -e 's/\(InfoValue:\)\s.*/\1\ /g' | \
  6. sed -e 's/\(PdfID[0-9]\+:\)\s.*/\1\ /g' | \
  7. pdftk "$inf" update_info - output "$outf-tmp"
  8. exiftool -m -all:all= -overwrite_original "$outf-tmp"
  9. qpdf --linearize "$outf-tmp" "$outf"
  10. redact=$(pdftk "$outf" dump_data | \
  11. grep -e '^PdfID[0-9]\+:\s[0-9a-f]\{32\}' | \
  12. sed 's/^[^:]\+:\s//'
  13. )
  14. pdfid=$(echo "$tag" | cat - master_template.svg | sha256sum | cut -d" " -f1 | head -c32)
  15. while read rstr
  16. do
  17. sed -i "$outf" -e "s/$rstr/$pdfid/"
  18. done <<< "$redact"
  19. rm "$outf-tmp"