Created
June 6, 2018 19:14
-
-
Save gm3dmo/9ee76ffb0167f047b7810fe6ca7b1430 to your computer and use it in GitHub Desktop.
watermarker script to overlay a pdf onto another pdf with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from an article by Mike Driscoll: | |
# http://www.blog.pythonlibrary.org/2018/06/06/creating-and-manipulating-pdfs-with-pdfrw/ | |
from pdfrw import PdfReader, PdfWriter, PageMerge | |
def watermarker(path, watermark, output): | |
base_pdf = PdfReader(path) | |
watermark_pdf = PdfReader(watermark) | |
mark = watermark_pdf.pages[0] | |
for page in range(len(base_pdf.pages)): | |
merger = PageMerge(base_pdf.pages[page]) | |
merger.add(mark).render() | |
writer = PdfWriter() | |
writer.write(output, base_pdf) | |
if __name__ == '__main__': | |
watermarker('uc491-a.pdf', | |
'uc491-b.pdf', | |
'uc491b-on-top-uc491a.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment