-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwater.py
More file actions
28 lines (26 loc) · 813 Bytes
/
water.py
File metadata and controls
28 lines (26 loc) · 813 Bytes
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
import sys
import os
def remove_watermark(keyword, source, destination=None):
f_name = source.split(".")[0]
t = f_name + '_t.pdf'
if not destination:
destination = f_name + "_clean.pdf"
os.system('qpdf --stream-data=uncompress ' + source + ' ' + t)
book = open(t, "rb")
book_clean = open(destination,"wb")
keep, obj = True, ''
for line in book:
if ' obj' in line:
if keep: book_clean.write(obj)
keep, obj = True, ''
elif keyword in line:
keep = False
obj += line
if keep: book_clean.write(obj)
os.system('rm ' + t)
print 'Success! Wrote to ' + destination + '.'
if __name__ == '__main__':
"""
Usage ./water.py keyword source.pdf [destination.pdf]
"""
remove_watermark(*sys.argv[1:])