-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrm_watermark.py
29 lines (24 loc) · 957 Bytes
/
rm_watermark.py
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
# import the necessary modules
import PyPDF2
# define the list of PDF files
pdf_files = ['file1.pdf', 'file2.pdf', ..., 'file_X.pdf']
# iterate over the PDF files
for pdf_file in pdf_files:
# open the PDF file in read-binary mode
with open(pdf_file, 'rb') as file:
# create a PDF object
pdf = PyPDF2.PdfFileReader(file)
# create a PDF object for the output file
output_pdf = PyPDF2.PdfFileWriter()
# iterate over the pages of the PDF
for page in range(pdf.getNumPages()):
# get the current page
current_page = pdf.getPage(page)
# remove the watermark
current_page.mergePage(current_page)
# add the modified page to the output PDF
output_pdf.addPage(current_page)
# open the output PDF file in write-binary mode
with open(pdf_file[:-4] + '_modified.pdf', 'wb') as output:
# write the modified PDF to the output file
output_pdf.write(output)