-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from aarjavpatni/pdf-merger
PDF Merger
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |