forked from CoderWanFeng/python-office
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecryptionPDF.py
More file actions
46 lines (34 loc) · 1.39 KB
/
Copy pathdecryptionPDF.py
File metadata and controls
46 lines (34 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# coding:utf-8
from pathlib import Path
from PyPDF2 import PdfFileReader, PdfFileWriter
from customizeWindowPyfile.ProgressBarDialog import ProgressBar
def decryptionPDF(pdfPath, password):
src_folder = Path(pdfPath)
file_list = list(src_folder.glob('*加密.pdf'))
print(file_list)
totalTaskNum = len(file_list)
doneTaskNum = 0
currentTaskNum = 1
bar = ProgressBar()
bar.show()
for pdf in file_list:
inputfile = PdfFileReader(str(pdf))
outputfile = PdfFileWriter()
bar.setProcessOnTiTle(currentTaskNum, totalTaskNum)
if inputfile.isEncrypted:
inputfile.decrypt(password)
pageCount = inputfile.getNumPages()
for page in range(pageCount):
outputfile.addPage(inputfile.getPage(page))
des_name = f'{pdf.stem}_解密.pdf'
des_file = src_folder / des_name
with open(des_file, 'wb') as f_out:
outputfile.write(f_out)
doneTaskNum = doneTaskNum + 1
currentTaskNum = currentTaskNum + 1
print(currentTaskNum)
print(100 * doneTaskNum / totalTaskNum)
bar.setValue(100 * doneTaskNum / totalTaskNum, 100 * (doneTaskNum - 1) / totalTaskNum,
100 * totalTaskNum / totalTaskNum)
if __name__ == '__main__':
decryptionPDF('D:\Desktop\功能测试\PDF文件', '12345')