Skip to content

Commit

Permalink
Create mergepdf.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kuldeep27396 authored Apr 30, 2020
1 parent 6e487cd commit 4efd72e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mergepdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

import PyPDF2

pdffile =[]

for filename in os.listdir('.'):
if filename.endswith('.pdf'):
pdffile.append(filename)

pdffile.sort()

pdf_write = PyPDF2.PdfFileWriter()

for filename in pdffile:
obj = open(filename,'rb')
read = PyPDF2.PdfFileWriter(obj)
for pgn in range(1,read.numPages):
pgo = read.getPage(pgn)
pdf_write.addPage(pgo)

output_file = open(filename,'wb')
pdf_write.write(output_file)
output_file.close()

0 comments on commit 4efd72e

Please sign in to comment.