- If you don't have xpdf already:
brew install xpdf- Convert the PDF to a postscript file:
pdftops in.pdf- Open the PS file in a text editor and locate the watermark elements. Look for a way to identify them throughout the file. For example, the watermark code may be a fixed length and contain some keyword.
- Strip the postscript of the watermark code. For example, if the watermark code stretches 35 lines before and 70 lines after
PATTERNyou could use:
vim -c 'g/PATTERN/-35,+70d' -c 'w! out.ps|q!' in.ps- Compile the postscript back into PDF:
ps2pdf out.ps-
Finding the start and end of the watermark code can be tricky. If you notice it is preceeded by opening tags
qwhich are later closed withQyou can ensure you have captured all closing tags with the following command:ack -B 35 -A 70 'PATTERN' in.ps | tee >(ack -c '^Q$') >(ack -c '^q$') >/dev/null
To remove an annoying link:
pdftk in.pdf output temp.pdf uncompress
vim -c 'g#\V/URI (http://www.example.com/)#-6,+7d' -c 'w! temp.pdf|q!' temp.pdf
LANG=C sed -E -i '' 's/www.example.com/ /' temp.pdf
pdftk temp.pdf output out.pdf compress