Skip to content

Instantly share code, notes, and snippets.

@mdp
Last active May 22, 2021 07:53
Show Gist options
  • Save mdp/fa006825885980f4abf4125dd8ec08c8 to your computer and use it in GitHub Desktop.
Save mdp/fa006825885980f4abf4125dd8ec08c8 to your computer and use it in GitHub Desktop.
Magically watermark your PDF's in bulk

Requirements

_Assumes you are on OSX (sorry, I didn't have time to test it on linux)

Usage

./watermark.sh mydoc.pdf < recipients.txt

#!/bin/bash
mkdir out
filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"
while read line
do
echo "Watermarking $line"
convert -background transparent \
-fill rgba\(0,0,0,0.12\) -rotate 45 \
-pointsize 96 label:"$line - Confidential" \
-trim +repage watermark.pdf
output="$filename-${line//[[:blank:]]/}"
echo "Saving to $output.pdf"
pdftk $1 multistamp watermark.pdf output out/$output.pdf
done
rm watermark.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment