File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Python program to split large pdf(typically textbook) into small set of pdfs, maybe chapterwise
3
+ to enhance the experience of reading and feasibility to study only specific parts from the large original textbook
4
+ """
5
+
6
+
7
+ import PyPDF2
8
+ path = input ()
9
+ merged_pdf = open (path , mode = 'rb' )
10
+
11
+
12
+ pdf = PyPDF2 .PdfFileReader (merged_pdf )
13
+
14
+ (u , ctr , x ) = tuple ([0 ]* 3 )
15
+ for i in range (1 , pdf .numPages + 1 ):
16
+
17
+ if u >= pdf .numPages :
18
+ print ("Successfully done!" )
19
+ exit (0 )
20
+ name = input ("Enter the name of the pdf: " )
21
+ ctr = int (input (f"Enter the number of pages for { name } : " ))
22
+ u += ctr
23
+ if u > pdf .numPages :
24
+ print ('Limit exceeded! ' )
25
+ break
26
+
27
+ base_path = '/Users/darpan/Desktop/{}.pdf'
28
+ path = base_path .format (name )
29
+ f = open (path , mode = 'wb' )
30
+ pdf_writer = PyPDF2 .PdfFileWriter ()
31
+
32
+ for j in range (x , x + ctr ):
33
+ page = pdf .getPage (j )
34
+ pdf_writer .addPage (page )
35
+
36
+ x += ctr
37
+
38
+ pdf_writer .write (f )
39
+ f .close ()
40
+
41
+
42
+ merged_pdf .close ()
43
+ print ("Successfully done!" )
You can’t perform that action at this time.
0 commit comments