Last active
July 18, 2017 18:48
-
-
Save rtluckie/97ea11871fa7e4cd09cce8b2840aca3a to your computer and use it in GitHub Desktop.
Removes annoying watermark links from it-ebooks pdfs
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euf -o pipefail | |
# Usage | |
# ./unwatermark.sh it-ebooks.info sharefactory.com somefile.pdf | |
TARGET_PDF=${@: -1} | |
TARGET_PATH=$(dirname $TARGET_PDF) | |
BACKUP_PDF=$(echo $TARGET_PDF | sed "s/.pdf$/.pdf.bak/g") | |
TMP_PDF=$TARGET_PDF.tmp | |
NEEDLES=${@:1:$(($#-1))} | |
if [[ ! -f $TARGET_PDF ]]; then | |
echo 'bad file' | |
exit 1 | |
fi | |
cp -pr $TARGET_PDF $TMP_PDF | |
cp -pr $TARGET_PDF $BACKUP_PDF | |
for NEEDLE in $NEEDLES; do | |
sed -i -e "s/\/URI (.*$NEEDLE.*/I,-5 d /g" -e "s/.*$NEEDLE.*//g" $TMP_PDF | |
done | |
pdftk $TMP_PDF output $TARGET_PDF | |
rm -fr $TMP_PDF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment