I am trying to put a watermark on a pdf but when I run the code it does nothing , It does not create the output file what did I missed?
# pdf watermarkerV2
import PyPDF2
template = PyPDF2.PdfFileReader(open('super.pdf', 'rb'))
watermark = PyPDF2.PdfFileReader(open('wtr.pdf', 'rb'))
output = PyPDF2.PdfFileWriter()
for i in range(template.getNumPages()):
page = template.getPage(i)
page.mergePage(watermark.getPage(0))
output.addPage(page)
with open('watermarked.pdf', 'wb') as file:
output.write(file)
CodePudding user response:
Your with
clause was within the for
loop.
This will work:
import PyPDF2
template = PyPDF2.PdfFileReader(open('super.pdf', 'rb'))
watermark = PyPDF2.PdfFileReader(open('wtr.pdf', 'rb'))
output = PyPDF2.PdfFileWriter()
for i in range(template.getNumPages()):
page = template.getPage(i)
page.mergePage(watermark.getPage(0))
output.addPage(page)
with open('watermarked.pdf', 'wb') as file:
output.write(file)
CodePudding user response:
Hays silly me The pdf Super.pdf was empty that is why there is an OS error [errno 22] thanks for the help guys :D