Removes all metadata from one or more PDF files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
997 B

#!/bin/bash
# A very simple script by Max Mehl: mail@mehl.mx
# Removes all metadata from a PDF file located in the same dir like the script
# This happens by the usage of pdftk, a powerful command line tool on GNU/Linux
# change to directory where the script resides if tool is called by cron
cd "$(dirname "$(readlink -f "$0")")"
ls *.pdf > /dev/null 2>&1
if [ "$?" = "0" ]; then
mkdir ./temp # create temporary directory
cp ./*.pdf ./temp
else
echo "No files found"
exit 1
fi
# Replace spaces with underscores
for FILE in ./temp/*.pdf; do
rename "s/ /_/g" "$DATEI" > /dev/null 2>&1;
done
for i in $( find ./temp -type f -name "*.pdf" ); # filename with path in $i
do
FILENAME=`basename $i` # filename without path
# Dump data in temporary file
pdftk $i dump_data output $i.meta
sed 's/InfoValue:.*/InfoValue:/g' $i.meta > $i.meta.clean
pdftk $i update_info $i.meta.clean output $FILENAME # Update Metadata from cleaned metafile and write to original file
done
rm -r ./temp