Skip to content

Instantly share code, notes, and snippets.

@bikz05
Created December 6, 2014 00:13
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save bikz05/fc04b279e3460ec90dcc to your computer and use it in GitHub Desktop.
Save bikz05/fc04b279e3460ec90dcc to your computer and use it in GitHub Desktop.
Shell script to remove text from PDF using pdftk
echo $"Script Written by $(tput setaf 5)Bikram Hanzra$(tput sgr 0) (bikz.05@gmail.com)"$
if [ "$#" == 0 ] ; then
echo "$(tput setaf 1)We need at least 2 arguments"
echo "SYNTAX ./remove <file-name> <text-to-be-removed>"
echo "<text-to-be-removed> by default = www.it-ebooks.info$(tput sgr 0)"
exit
fi
if [ "$#" == 1 ] ; then
echo "$(tput setaf 1)CAVEAT$(tput sgr 0) -> Will remove occurances of -> $(tput setaf 1)"www.it-ebooks.info"$(tput sgr 0)"
set -- "${@:1}" "www.it-ebooks.info"
fi
# Display files names
echo "$(tput setaf 4)File Name ->" "$1"$'\n'"Text to be removed-> " "$2 $(tput sgr 0)"
# Include the watermark
sed -e "s/"$2"/ /g" <"$1" >unwatermarked.pdf && pdftk unwatermarked.pdf output fixed.pdf && mv fixed.pdf unwatermarked.pdf
mv unwatermarked.pdf "$1"
echo "$(tput setaf 4)Removing Watermark Successful :)$(tput sgr 0)"
@bikz05
Copy link
Author

bikz05 commented Dec 6, 2014

HOW TO USE THIS SCRIPT

./remove_txt <file-name> <text-to-be-removed>
  1. First argument is name of the pdf file
  2. Second argument is the text that you want to remove

REMEMBER

1. To make the script executable by using -
chmod +x remove_txt

PACKAGE DEPENDENCIES

1. `sed` 2. `pdftk` To install these packages, use the following command -
sudo apt-get install sed pdftk

REFERENCE

1. [Related SuperUser thread](http://superuser.com/questions/448519/how-to-remove-watermark-from-pdf-using-pdftk)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment