Created
March 21, 2023 14:18
-
-
Save meksor/e9fc564765ee54e357a5b0d571aa112e to your computer and use it in GitHub Desktop.
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
import pypdf | |
import glob | |
from pathlib import Path | |
files = "2022/*/*.pdf" | |
with open("Unterschrift.pdf", "rb") as overlay: | |
for file in glob.glob(files): | |
with open(file, "rb") as inFile: | |
original = pypdf.PdfReader(inFile) | |
background = original.pages[0] | |
foreground = pypdf.PdfReader(overlay).pages[0] | |
# merge the first two pages | |
background.merge_page(foreground) | |
# add all pages to a writer | |
writer = pypdf.PdfWriter() | |
for page in original.pages: | |
writer.add_page(page) | |
# write everything in the writer to a file | |
outpath = "out/" + file | |
Path(outpath).parent.mkdir(exist_ok=True, parents=True) | |
with open(outpath, "wb") as outFile: | |
writer.write(outFile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment