Advertisement
steve-shambles-2109

166-Merge Two or more PDFS into one

Oct 15th, 2019
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. """
  2. Python code snippets vol 34:
  3.  
  4. 166-Merge Two or more PDFS into one
  5. stevepython.wordpress.com
  6.  
  7. pip install PyPDF2
  8.  
  9. Tested on: Win 7\Linux Mint 19.1
  10.  
  11. Source:
  12. https://snipplr.com/view/328728/merge-multiple-pdf-documents/
  13. """
  14.  
  15. import time
  16. import os
  17. from PyPDF2 import PdfFileMerger
  18.  
  19. # Any .pdf files found in current dir will be merged into one pdf file.
  20. allPDFs = [a for a in os.listdir() if a.endswith(".pdf")]
  21.  
  22. dtFname = time.strftime("%Y%m%d_%H%M%S")
  23. merger = PdfFileMerger()
  24.  
  25. for pdf in allPDFs:
  26.     merger.append(pdf)
  27.  
  28. merger.write(dtFname + ".pdf")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement