Spaces:
Sleeping
Sleeping
Delete pdfpass.py
Browse files- pdfpass.py +0 -20
pdfpass.py
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
from pypdf import PdfReader, PdfWriter
|
2 |
-
from io import BytesIO
|
3 |
-
|
4 |
-
def 移除_pdf密碼(pdf檔案, 密碼):
|
5 |
-
"""
|
6 |
-
解鎖帶有密碼保護的 PDF 檔案,回傳已解鎖的檔案(BytesIO)或錯誤訊息
|
7 |
-
"""
|
8 |
-
try:
|
9 |
-
reader = PdfReader(pdf檔案)
|
10 |
-
if reader.is_encrypted:
|
11 |
-
reader.decrypt(密碼)
|
12 |
-
writer = PdfWriter()
|
13 |
-
for page in reader.pages:
|
14 |
-
writer.add_page(page)
|
15 |
-
output = BytesIO()
|
16 |
-
writer.write(output)
|
17 |
-
output.seek(0)
|
18 |
-
return output
|
19 |
-
except Exception as e:
|
20 |
-
return f"解鎖失敗:{e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|