Posted By

richramo on 07/22/18


Tagged

#pdf #python


Versions (?)

Merge Multiple PDF Documents


 / Published in: Python
 

Merge multiple PDF documents that are stored in the same directory. File name is stored as the date and time of creation.

  1. import time
  2. import os
  3. from PyPDF2 import PdfFileMerger
  4.  
  5. # pdfs = ['test1.pdf', 'test2.pdf']
  6.  
  7. allPDFs = [a for a in os.listdir() if a.endswith(".pdf")]
  8.  
  9. dtFname = time.strftime("%Y%m%d_%H%M%S")
  10. merger = PdfFileMerger()
  11.  
  12. for pdf in allPDFs:
  13. merger.append(pdf)
  14.  
  15. merger.write(dtFname + ".pdf")

Report this snippet  

You need to login to post a comment.