File tree Expand file tree Collapse file tree 5 files changed +57
-0
lines changed Expand file tree Collapse file tree 5 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Merge two pdf Files
2
+
3
+ ### Third Party Libraries Required :
4
+ 1.PyPDF2
5
+
6
+ ### How to install above Library
7
+ ```
8
+ import PyPDF2
9
+ ```
10
+
11
+ ### How to use it :
12
+ 1 . Download or clone the repository
13
+ 2 . Install Required Libraries
14
+ 3 . Run merge.py
15
+ 4 . you will be asked to give the path of two pdf files
16
+ 5 . you will get the merged pdf in the same directory
17
+
18
+ ### Output
19
+ I have added the merged pdf file named as MergedFiles.pdf which is formed from pdf1.pdf pdf2.pdf .
20
+ You can check the final output in MergedFiles.pdf File
21
+
22
+ ![ built with love] ( https://forthebadge.com/images/badges/built-with-love.svg )
23
+
24
+ Check out my Github profile [ Tejas1510!] ( https://github.com/Tejas1510 )
Original file line number Diff line number Diff line change
1
+ import PyPDF2
2
+
3
+ # Open the pdf file
4
+ file1 = input ("Enter the path of pdf1 : " )
5
+ file2 = input ("Enter the path of pdf2 : " )
6
+ pdf1 = open (file1 , 'rb' )
7
+ pdf2 = open (file2 , 'rb' )
8
+
9
+ # Read the files
10
+ reader1 = PyPDF2 .PdfFileReader (pdf1 )
11
+ reader2 = PyPDF2 .PdfFileReader (pdf2 )
12
+
13
+ # Create a new PdfFileWriter object which represents a blank PDF document
14
+ writer = PyPDF2 .PdfFileWriter ()
15
+
16
+ # Loop through all the pagenumbers for the first document
17
+ for i in range (reader1 .numPages ):
18
+ pages = reader1 .getPage (i )
19
+ writer .addPage (pages )
20
+
21
+ # Loop through all the pagenumbers for the second document
22
+ for i in range (reader2 .numPages ):
23
+ pages = reader2 .getPage (i )
24
+ writer .addPage (pages )
25
+
26
+ # Now that you have copied all the pages in both the documents, write them into the a new document
27
+ mergedfile = open ('MergedFiles.pdf' , 'wb' )
28
+ writer .write (mergedfile )
29
+
30
+ # Close all the files - Created as well as opened
31
+ mergedfile .close ()
32
+ pdf1 .close ()
33
+ pdf2 .close ()
You can’t perform that action at this time.
0 commit comments