Advertisement
wagner-cipriano

Join Many PDF Files into one (Merge PDF)

Nov 20th, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Nov 20 11:51:48 2018
  4. @author: wagner
  5. """
  6.  
  7. #Imports:
  8. from PyPDF2 import PdfFileMerger, PdfFileReader, PdfFileWriter
  9.  
  10.  
  11. def pdf_add_page():
  12.     output = PdfFileWriter()
  13.     for FileName in FileList:
  14.         filename1 = '%s/%s.pdf' %(path, FileName)
  15.         file1 = PdfFileReader(file(filename1, "rb"))
  16.         output.addPage(file1.getPage())
  17.  
  18.     filename2 = '%s/%s.pdf' %(path, 'file_pdf_full')
  19.     outputStream = file(filename2, "wb")
  20.     output.write(outputStream)
  21.     outputStream.close()
  22.  
  23. path = '/home/wagner/SSI/BancoInter/'
  24. FileList = ['file_pdf_pag1-3', 'file_pdf_pag3-5']
  25.  
  26. merger = PdfFileMerger()
  27. for FileName in FileList:
  28.     filename1 = '%s/%s.pdf' %(path, FileName)
  29.     merger.append(PdfFileReader(file(filename1, 'rb')))
  30. filename2 = '%s/%s.pdf' %(path, 'file_pdf_full')
  31. merger.write(filename2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement