Skip to content

Instantly share code, notes, and snippets.

@luanvuhlu
Created April 19, 2023 09:46
Show Gist options
  • Save luanvuhlu/b8d43c7d5d4aa0d3f437bf622a695b63 to your computer and use it in GitHub Desktop.
Save luanvuhlu/b8d43c7d5d4aa0d3f437bf622a695b63 to your computer and use it in GitHub Desktop.
merge all pdf files in a folder https://stackoverflow.com/a/47356404
pip install PyPDF2
import os
from PyPDF2 import PdfMerger
x = [a for a in os.listdir() if a.endswith(".pdf")]
merger = PdfMerger()
for pdf in x:
merger.append(open(pdf, 'rb'))
with open("result.pdf", "wb") as fout:
merger.write(fout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment