@@ -12,32 +12,34 @@ def pdf_info(self):
12
12
13
13
14
14
def split_pdf_each (self ):
15
- try :
16
- pdf_input = PdfFileReader (open (self .infn [0 ], 'rb' ))
17
- pages = pdf_input .getNumPages ()
18
- self .message = '正在拆分...'
19
- for i in range (pages ):
20
- pdf_output = PdfFileWriter ()
21
- pdf_output .addPage (pdf_input .getPage (i ))
22
- pdf_output .write (open (self .infn [0 ][:- 4 ] + '-' + str (i + 1 ) + '.pdf' , 'wb' ))
23
- self .message = '已拆分%.2f' % ((i + 1 )/ pages * 100 ) + '%'
24
- self .message = '拆分完成'
25
- except :
26
- self .message = '出错了,请检查输入格式是否正确'
15
+ for infn in self .infn :
16
+ try :
17
+ pdf_input = PdfFileReader (open (infn , 'rb' ))
18
+ pages = pdf_input .getNumPages ()
19
+ self .message = '正在拆分...'
20
+ for i in range (pages ):
21
+ pdf_output = PdfFileWriter ()
22
+ pdf_output .addPage (pdf_input .getPage (i ))
23
+ pdf_output .write (open (infn [:- 4 ] + '-' + str (i + 1 ) + '.pdf' , 'wb' ))
24
+ self .message = '已拆分%.2f' % ((i + 1 )/ pages * 100 ) + '%'
25
+ self .message = '拆分完成'
26
+ except :
27
+ self .message = '出错了,请检查输入格式是否正确'
27
28
28
29
def split_pdf_parts (self ):
29
- try :
30
- pdf_input = PdfFileReader (open (self .infn [0 ], 'rb' ))
31
- self .message = '正在拆分...'
32
- for part in self .params :
33
- pdf_output = PdfFileWriter ()
34
- for i in range (part [0 ] - 1 , part [1 ]):
35
- pdf_output .addPage (pdf_input .getPage (i ));
36
- pdf_output .write (open (self .infn [0 ][:- 4 ] + '-' + str (part [0 ]) + '-' + str (part [1 ]) + '.pdf' , 'wb' ))
37
- self .message = '第%d部分已拆分' % (self .params .index (part ) + 1 )
38
- self .message = '拆分完成'
39
- except :
40
- self .message = '出错了,请检查输入格式是否正确'
30
+ for infn in self .infn :
31
+ try :
32
+ pdf_input = PdfFileReader (open (infn , 'rb' ))
33
+ self .message = '正在拆分...'
34
+ for part in self .params :
35
+ pdf_output = PdfFileWriter ()
36
+ for i in range (part [0 ] - 1 , part [1 ]):
37
+ pdf_output .addPage (pdf_input .getPage (i ));
38
+ pdf_output .write (open (infn [:- 4 ] + '-' + str (part [0 ]) + '-' + str (part [1 ]) + '.pdf' , 'wb' ))
39
+ self .message = '第%d部分已拆分' % (self .params .index (part ) + 1 )
40
+ self .message = '拆分完成'
41
+ except :
42
+ self .message = '出错了,请检查输入格式是否正确'
41
43
42
44
def merge_pdf (self ):
43
45
try :
@@ -96,11 +98,11 @@ def rotate_pdf(self):
96
98
self .message = '出错了,请检查输入格式是否正确(旋转角度为90的倍数)'
97
99
98
100
def add_watermark (self ):
99
- try :
100
- self . message = '正在添加页码'
101
- water_pdf = PdfFileReader ( open ( 'page-number.pdf' , 'rb' ));
102
- water_pages = water_pdf . getNumPages ()
103
- for infn in self . infn :
101
+ self . message = '正在添加页码'
102
+ water_pdf = PdfFileReader ( open ( 'page-number.pdf' , 'rb' ));
103
+ water_pages = water_pdf . getNumPages ()
104
+ for infn in self . infn :
105
+ try :
104
106
pdf_input = PdfFileReader (open (infn , 'rb' ));
105
107
pages = min (pdf_input .getNumPages (), water_pages );
106
108
pdf_output = PdfFileWriter ();
@@ -111,6 +113,7 @@ def add_watermark(self):
111
113
pdf_output .addPage (page );
112
114
self .message = str (i ) + '/' + str (pages ) + ': ' + infn
113
115
pdf_output .write (open (infn [:- 4 ] + '-number2.pdf' , 'wb' ));
114
- self .message = '页码添加完成'
115
- except :
116
- self .message = '出错了,请检查输入格式是否正确(page-number.pdf文件要求和程序在同一目录)'
116
+ self .message = '页码添加完成'
117
+ except :
118
+ self .message = '出错了,请检查输入格式是否正确(page-number.pdf文件要求和程序在同一目录)'
119
+
0 commit comments