-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-watermark.sh
executable file
·43 lines (34 loc) · 1.46 KB
/
remove-watermark.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# Remove a textual watermark from a PDF file. Requires qpdf and pdftx
# to work correctly. The correct usage is
#
# remove-watermark WATERMARK "Your Input File.pdf" "Your Output File.pdf"
# https://gist.githubusercontent.com/elfsternberg/a96883018d783cbbad7b454ecd0a7ffe/raw/8a03d341c480324ad6611c0fd5150bb3ca10e16a/remove-watermark.sh
WATERMARK=$1
INBOUND=$2
OUTBOUND=$3
echo "s%$WATERMARK%$BLANKS%g"
UNCOMPRESSED=`mktemp --dry-run 'uncompressed-XXXXXXXXXX.pdf'`
FIXED=`mktemp --dry-run 'fixed-XXXXXXXXXX.pdf'`
UNMARKED=`mktemp --dry-run 'unmarked-XXXXXXXXXX.pdf'`
WATERMARK2=${WATERMARK//\\/}
echo $WATERMARK
echo $WATERMARK2
WATERMARKLEN=${#WATERMARK2}
WATERMARKLEN1=${#WATERMARK}
echo $WATERMARKLEN $WATERMARKLEN1
BLANKS=`printf %${WATERMARKLEN}s`
qpdf --stream-data=uncompress "$INBOUND" $UNCOMPRESSED
sed -ze "s%$WATERMARK%$BLANKS%g" < $UNCOMPRESSED > $FIXED
pdftk $FIXED output $UNMARKED
qpdf --stream-data=compress $UNMARKED "$OUTBOUND"
rm $UNCOMPRESSED $FIXED $UNMARKED
# NO WARRANTY
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.