Skip to content

Commit

Permalink
Merge pull request #40 from aarjavpatni/pdf-merger
Browse files Browse the repository at this point in the history
PDF Merger
  • Loading branch information
kishanrajput23 authored Oct 1, 2022
2 parents 3ebe589 + 1983297 commit 1003a04
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions merge_pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from PyPDF4 import PdfFileReader, PdfFileWriter

def merge_pdfs(paths, output):
pdf_writer = PdfFileWriter()

for path in paths:
pdf_reader = PdfFileReader(path)
for page in range(pdf_reader.getNumPages()):
# Add each page to the writer object
pdf_writer.addPage(pdf_reader.getPage(page))

# Write out the merged PDF
with open(output, 'wb') as out:
pdf_writer.write(out)

file1 = input("Enter the path of the first file: ")
file2 = input("Enter the path of the second file: ")
output = input("Enter the name of the output file: ")

if __name__ == '__main__':
paths = [file1, file2]
merge_pdfs(paths, output= output + ".pdf")

0 comments on commit 1003a04

Please sign in to comment.