Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # USAGE: removewatermark file.pdf
- # outputs to $OUTDIR/file.pdf
- # How to use this script to remove watermarks from PDF documents on OS X (MacOS):
- #
- # 1. port install qpdf
- #
- # 2. normally, you would also run "port install pdftk" but that doesn't work
- # on os X 10.11+ as of 2016-11, so instead download the installer from pdflabs
- # referenced in http://stackoverflow.com/a/33248310.
- #
- # 3. Write a program called "stripwm" that removes all watermarks from the
- # uncompressed pdf read from standard input and writes the result to standard
- # output. Save it in the current directory, or change the STRIPWM variable
- # to point to its location. See below for an example.
- #
- # References:
- #
- # http://superuser.com/questions/455462/how-to-remove-a-watermark-from-a-pdf-file
- OUTDIR=fixed
- STRIPWM=./stripwm
- DECRYPTED=$(mktemp /tmp/fixit.XXXXXX)
- UNCOMPRESSED=$(mktemp /tmp/fixit.XXXXXX)
- DONE=$(mktemp /tmp/fixit.XXXXXX)
- qpdf --decrypt "$1" "${DECRYPTED}"
- pdftk "${DECRYPTED}" output "${UNCOMPRESSED}" uncompress
- "${STRIPWM}" <"${UNCOMPRESSED}" >"${DONE}"
- pdftk "${DONE}" output "${OUTDIR}/$1" compress
- # Here is an example to remove watermarks from MAA books:
- <<STRIPWM
- #!/usr/bin/perl
- $_ = join("", <>);
- s~
- (\n\d+\s+\d+\s+obj\s+
- <<\s+
- /Length\s+\d+\s+
- >>\s+
- stream\s+)
- Q\s+
- q\s+
- BT\s+
- 0\s+0\s+0\s+rg\s+
- [^\n]*Tf\s+
- [^\n]+Tm\s+
- [^\n]*Your\s+Name[^\n]*Tj\s+
- [^\n]*Tm\s+
- ET\s+
- Q\s+
- (endstream\s+
- endobj[^\S\n]*\n)~$1$2~sgx;
- print;
- STRIPWM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement