Skip to content

Instantly share code, notes, and snippets.

@sueszli
Created August 8, 2023 23:52
Show Gist options
  • Save sueszli/68fd380b01e4b52852d9ac0b3fa5b961 to your computer and use it in GitHub Desktop.
Save sueszli/68fd380b01e4b52852d9ac0b3fa5b961 to your computer and use it in GitHub Desktop.
merge pdf files together
from PyPDF2 import PdfFileMerger
import os
inputPath = "./extractedPages"
total = len(os.listdir(inputPath))
count = 1
merger = PdfFileMerger()
for pdf in os.listdir(inputPath):
merger.append(open(inputPath + "/" + pdf, "rb"))
print("merged [" + str(count) + "/" + str(total) + "] ...", pdf)
count += 1
with open("merged.pdf", "wb") as out:
merger.write(out)
print("Merged all pages")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment