-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathpdf.py
More file actions
35 lines (18 loc) · 691 Bytes
/
Copy pathpdf.py
File metadata and controls
35 lines (18 loc) · 691 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
29
30
31
32
33
34
35
# OLD: import PyPDF2
# NEW:
import pypdf
# template = PyPDF2.PdfFileReader(open('superduper.pdf', 'rb'))
# watermark = PyPDF2.PdfFileReader(open('water.pdf', 'rb'))
# output = PyPDF2.PdfFileWriter()
# THIS IS THE NEW WAY TO DO THIS:
template = pypdf.PdfReader(open('superduper.pdf', 'rb'))
watermark = pypdf.PdfReader(open('water.pdf', 'rb'))
output = pypdf.PdfWriter()
# for i in range(template.getNumPages()):
# THIS IS THE NEW WAY TO DO THIS:
for i in range(len(template.pages)):
page = template.pages[i]
page.merge_page(watermark.pages[0])
output.add_page(page)
with open('watermaked_output.pdf', 'wb') as outputFile:
output.write(outputFile)