This repository has been archived by the owner on Sep 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_watermark
executable file
·56 lines (50 loc) · 1.73 KB
/
remove_watermark
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
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /bin/bash
# Remove "Solidworks Student Edition. For Academic Use Only" watermarks
# from your PDFs. Those can be annoying when they cover up your tables and
# stuff like that. Authors of technical drawings, even student authors,
# deserve full control over how their drawings are displayed.
# Copyright © 2014–2015 Repentinus <repentinus plus sw at fsfe dot org>
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
if [[ $# -lt 1 ]]; then
echo 'Usage: remove_watermark file1 [file*]'
exit 1
fi
for file in "$@"
do
tmp=$(mktemp -t remove_watermark.$$.XXXXXXXXXX)
e=$?
tmp2=$(mktemp -t remove_watermark.$$.XXXXXXXXXX)
let "e = $e + $?"
if [[ e -ne 0 ]]; then
echo "Failed to create temporary files."
exit 2
fi
qpdf=$(qpdf --stream-data=uncompress "$file" $tmp)
if [[ $? -ne 0 ]]; then
echo "Failed to uncompress $file. Skipping…"
echo $qpdf
rm $tmp $tmp2
continue
else
sed=$(sed -i 's/00360052004F004C0047003A00520055004E005600030036005700580047004800510057000300280047004C0057004C005200510011>Tj//g' $tmp && sed -i 's/<00030029005200550003002400460044004700480050004C00460003003800560048000300320051004F005C0011>Tj//g' $tmp)
if [[ $? -ne 0 ]]; then
echo "Watermark deletion for $file, $tmp failed. Skipping…"
echo $sed
rm $tmp $tmp2
continue
fi
qpdf=$(qpdf --stream-data=compress $tmp $tmp2)
# if [[ $? -ne 0 ]]; then
# echo "Compression of $file, $tmp failed. Skipping…"
# echo $qpdf
# rm $tmp $tmp2
# continue
# else
gs=$(gs -o $tmp -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress $tmp2)
mv $tmp "$file"
# fi
fi
done