Compare commits
3 Commits
f796f207ea
...
master
Author | SHA1 | Date | |
---|---|---|---|
d941ea3341 | |||
28981e8ede | |||
5052e8b746 |
9
pdf_unlock/.gitignore
vendored
Normal file
9
pdf_unlock/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
*.pdf
|
||||||
|
*.spec
|
||||||
|
tmp*
|
||||||
|
*.exe
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
example
|
||||||
|
Output
|
||||||
|
*build
|
22
pdf_unlock/install.reg
Normal file
22
pdf_unlock/install.reg
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
Windows Registry Editor Version 5.00
|
||||||
|
|
||||||
|
[HKEY_CLASSES_ROOT\SystemFileAssociations\.pdf\shell\RemovePermissions]
|
||||||
|
@="<22>Ƴ<EFBFBD>Ȩ<EFBFBD><C8A8>"
|
||||||
|
"MultiSelectModel"="Player"
|
||||||
|
|
||||||
|
[HKEY_CLASSES_ROOT\SystemFileAssociations\.pdf\shell\RemovePermissions\command]
|
||||||
|
@="\"C:\\Program Files\\pdfUnlock\\main.exe\" \"%1\""
|
||||||
|
|
||||||
|
REM <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><EFBFBD>˵<EFBFBD>
|
||||||
|
[HKEY_CLASSES_ROOT\Directory\shell\RemovePermissions]
|
||||||
|
@="<22>Ƴ<EFBFBD>PDFȨ<46><C8A8>"
|
||||||
|
|
||||||
|
[HKEY_CLASSES_ROOT\Directory\shell\RemovePermissions\command]
|
||||||
|
@="\"C:\\Program Files\\pdfUnlock\\main.exe\" \"%1\""
|
||||||
|
|
||||||
|
REM <EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><EFBFBD>˵<EFBFBD>
|
||||||
|
[HKEY_CLASSES_ROOT\Directory\Background\shell\RemovePermissions]
|
||||||
|
@="<22>Ƴ<EFBFBD>PDFȨ<46><C8A8>"
|
||||||
|
|
||||||
|
[HKEY_CLASSES_ROOT\Directory\Background\shell\RemovePermissions\command]
|
||||||
|
@="\"C:\\Program Files\\pdfUnlock\\main.exe\" \"%V\""
|
65
pdf_unlock/installer
Normal file
65
pdf_unlock/installer
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
; 脚本由 Inno Setup 脚本向导生成。
|
||||||
|
; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档!
|
||||||
|
|
||||||
|
#define MyAppName "PDF解密"
|
||||||
|
#define MyAppVersion "1.1"
|
||||||
|
#define MyAppPublisher "flt"
|
||||||
|
#define MyAppURL "https://www.flt6.top/"
|
||||||
|
|
||||||
|
[Setup]
|
||||||
|
; 注意:AppId 的值唯一标识此应用程序。不要在其他应用程序的安装程序中使用相同的 AppId 值。
|
||||||
|
; (若要生成新的 GUID,请在 IDE 中单击 "工具|生成 GUID"。)
|
||||||
|
AppId={{34569C2B-A980-4031-94E1-7CC15988EA75}
|
||||||
|
AppName={#MyAppName}
|
||||||
|
AppVersion={#MyAppVersion}
|
||||||
|
;AppVerName={#MyAppName} {#MyAppVersion}
|
||||||
|
AppPublisher={#MyAppPublisher}
|
||||||
|
AppPublisherURL={#MyAppURL}
|
||||||
|
AppSupportURL={#MyAppURL}
|
||||||
|
AppUpdatesURL={#MyAppURL}
|
||||||
|
DefaultDirName={autopf}\pdfUnlock
|
||||||
|
DefaultGroupName={#MyAppName}
|
||||||
|
; 取消注释以下行以在非管理员安装模式下运行 (仅为当前用户安装)。
|
||||||
|
;PrivilegesRequired=lowest
|
||||||
|
OutputBaseFilename=mysetup
|
||||||
|
SolidCompression=yes
|
||||||
|
WizardStyle=modern
|
||||||
|
|
||||||
|
[Languages]
|
||||||
|
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"
|
||||||
|
|
||||||
|
[Tasks]
|
||||||
|
Name: "pdfcontextmenu"; Description: "为PDF文件添加右键菜单"; GroupDescription: "上下文菜单:"; Flags: checkedonce
|
||||||
|
Name: "foldercontextmenu"; Description: "为文件夹添加右键菜单"; GroupDescription: "上下文菜单:"; Flags: checkedonce
|
||||||
|
Name: "folderbackgroundmenu"; Description: "为文件夹空白处添加右键菜单"; GroupDescription: "上下文菜单:"; Flags: checkedonce
|
||||||
|
|
||||||
|
[Files]
|
||||||
|
Source: "C:\git\tools-3\pdf_unlock\dist\main\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
|
||||||
|
; 注意:不要在任何共享系统文件上使用 "Flags: ignoreversion"
|
||||||
|
|
||||||
|
[Registry]
|
||||||
|
; PDF文件右键菜单
|
||||||
|
Root: HKCR; Subkey: "SystemFileAssociations\.pdf\shell\RemovePermissions"; ValueType: string; ValueName: ""; ValueData: "移除PDF权限"; Tasks: pdfcontextmenu; Flags: uninsdeletekey
|
||||||
|
Root: HKCR; Subkey: "SystemFileAssociations\.pdf\shell\RemovePermissions"; ValueType: string; ValueName: "MultiSelectModel"; ValueData: "Player"; Tasks: pdfcontextmenu
|
||||||
|
Root: HKCR; Subkey: "SystemFileAssociations\.pdf\shell\RemovePermissions\command"; ValueType: string; ValueName: ""; ValueData: """{app}\main.exe"" ""%1"""; Tasks: pdfcontextmenu
|
||||||
|
|
||||||
|
; 文件夹右键菜单
|
||||||
|
Root: HKCR; Subkey: "Directory\shell\RemovePermissions"; ValueType: string; ValueName: ""; ValueData: "移除PDF权限"; Tasks: foldercontextmenu; Flags: uninsdeletekey
|
||||||
|
Root: HKCR; Subkey: "Directory\shell\RemovePermissions\command"; ValueType: string; ValueName: ""; ValueData: """{app}\main.exe"" ""%1"""; Tasks: foldercontextmenu
|
||||||
|
|
||||||
|
; 文件夹背景右键菜单
|
||||||
|
Root: HKCR; Subkey: "Directory\Background\shell\RemovePermissions"; ValueType: string; ValueName: ""; ValueData: "移除PDF权限"; Tasks: folderbackgroundmenu; Flags: uninsdeletekey
|
||||||
|
Root: HKCR; Subkey: "Directory\Background\shell\RemovePermissions\command"; ValueType: string; ValueName: ""; ValueData: """{app}\main.exe"" ""%V"""; Tasks: folderbackgroundmenu
|
||||||
|
|
||||||
|
[Icons]
|
||||||
|
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
|
||||||
|
|
||||||
|
[UninstallDelete]
|
||||||
|
Type: files; Name: "{app}\*"
|
||||||
|
Type: dirifempty; Name: "{app}"
|
||||||
|
|
||||||
|
; [UninstallRun]
|
||||||
|
; 卸载时清理注册表项
|
||||||
|
; Filename: "reg"; Parameters: "delete ""HKCR\SystemFileAssociations\.pdf\shell\RemovePermissions"" /f"; Flags: runhidden; RunOnceId: "DelPDFMenu"
|
||||||
|
; Filename: "reg"; Parameters: "delete ""HKCR\Directory\shell\RemovePermissions"" /f"; Flags: runhidden; RunOnceId: "DelFolderMenu"
|
||||||
|
; Filename: "reg"; Parameters: "delete ""HKCR\Directory\Background\shell\RemovePermissions"" /f"; Flags: runhidden; RunOnceId: "DelBgMenu"
|
117
pdf_unlock/main.py
Normal file
117
pdf_unlock/main.py
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
import PyPDF2 # PyMuPDF
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
def copy_pdf_pages(input_path: str, output_path: str) -> bool:
|
||||||
|
"""
|
||||||
|
移除PDF文件的所有限制
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_path: 输入PDF文件路径
|
||||||
|
output_path: 输出PDF文件路径
|
||||||
|
password: PDF密码(如果有)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
是否成功移除限制
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
with open(input_path, 'rb') as input_file:
|
||||||
|
reader = PyPDF2.PdfReader(input_file)
|
||||||
|
|
||||||
|
writer = PyPDF2.PdfWriter()
|
||||||
|
|
||||||
|
# 复制所有页面
|
||||||
|
for page in reader.pages:
|
||||||
|
writer.add_page(page)
|
||||||
|
|
||||||
|
# 写入新文件(不设置任何加密或限制)
|
||||||
|
with open(output_path, 'wb') as output_file:
|
||||||
|
writer.write(output_file)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"移除PDF限制时发生错误: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# def copy_pdf_pages(input_file, output_file):
|
||||||
|
# """
|
||||||
|
# 读取PDF文件并逐页复制到新的PDF文件
|
||||||
|
|
||||||
|
# Args:
|
||||||
|
# input_file (str): 输入PDF文件路径
|
||||||
|
# output_file (str): 输出PDF文件路径
|
||||||
|
# """
|
||||||
|
# try:
|
||||||
|
# # 检查输入文件是否存在
|
||||||
|
# if not os.path.exists(input_file):
|
||||||
|
# print(f"错误:输入文件 '{input_file}' 不存在")
|
||||||
|
# return False
|
||||||
|
|
||||||
|
# # 打开输入PDF文件
|
||||||
|
# pdf_document = fitz.open(input_file)
|
||||||
|
|
||||||
|
# # 创建新的PDF文档
|
||||||
|
# new_pdf = fitz.open()
|
||||||
|
# new_pdf.insert_pdf(pdf_document)
|
||||||
|
|
||||||
|
# # 保存输出文件
|
||||||
|
# new_pdf.save(output_file)
|
||||||
|
|
||||||
|
# # 关闭文档
|
||||||
|
# pdf_document.close()
|
||||||
|
# new_pdf.close()
|
||||||
|
|
||||||
|
# return True
|
||||||
|
|
||||||
|
# except FileNotFoundError:
|
||||||
|
# print(f"错误:找不到文件 '{input_file}'")
|
||||||
|
# return False
|
||||||
|
# except PermissionError:
|
||||||
|
# print(f"错误:权限不足,无法访问文件")
|
||||||
|
# return False
|
||||||
|
# except Exception as pdf_error:
|
||||||
|
# error_msg = str(pdf_error).lower()
|
||||||
|
# if "damaged" in error_msg or "corrupt" in error_msg:
|
||||||
|
# print(f"错误:PDF文件 '{input_file}' 已损坏")
|
||||||
|
# else:
|
||||||
|
# print(f"发生错误:{str(pdf_error)}")
|
||||||
|
# return False
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""主函数"""
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print("用法:python main.py <输入PDF文件或目录>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
files = list(map(Path, sys.argv[1:]))
|
||||||
|
else:
|
||||||
|
input_path = Path(sys.argv[1])
|
||||||
|
if input_path.is_dir():
|
||||||
|
files = list(input_path.glob("**/*.pdf"))
|
||||||
|
else:
|
||||||
|
print("正在处理",input_path.name)
|
||||||
|
output_file = input_path.with_name(f"{input_path.stem}_decrypt.pdf")
|
||||||
|
success = copy_pdf_pages(input_path, output_file)
|
||||||
|
print("处理完成" if success else "处理失败")
|
||||||
|
return
|
||||||
|
|
||||||
|
total = len(files)
|
||||||
|
# 执行复制操作
|
||||||
|
for i, pdf_file in enumerate(files, start=1):
|
||||||
|
rate= round(i/total *100)
|
||||||
|
print(f"进度: ", "-"* (rate//5)," "*(20-rate//5), f" {rate}%",sep="",end="\r")
|
||||||
|
import time
|
||||||
|
# time.sleep(1) # 模拟处理时间
|
||||||
|
if not pdf_file.is_file():
|
||||||
|
print(f"跳过非PDF文件:{pdf_file}")
|
||||||
|
continue
|
||||||
|
output_file = pdf_file.with_name(f"{pdf_file.stem}_decrypt.pdf")
|
||||||
|
success = copy_pdf_pages(pdf_file, output_file)
|
||||||
|
|
||||||
|
if not success:
|
||||||
|
print(f"{pdf_file.name} 处理失败")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
1
pdf_unlock/requirements.txt
Normal file
1
pdf_unlock/requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
PyMuPDF==1.23.26
|
Reference in New Issue
Block a user