pdf查看密码

pdf有两种密码方式,一种是打开后进入文件内容页面后需要密码才能进行修改等操作,网上有很多方式进行移除密码操作,第二种是打开就需要密码,我这里简单记录一个暴力破解的方式,仅供参考

python 复制代码
import PyPDF2
import itertools
import string

def decrypt_pdf(input_file, output_file, password):
    with open(input_file, "rb") as file:
        reader = PyPDF2.PdfReader(file)

        if reader.is_encrypted:
            try:
                if reader.decrypt(password):
                    writer = PyPDF2.PdfWriter()

                    for page in reader.pages:
                        writer.add_page(page)

                    with open(output_file, "wb") as output_pdf_file:
                        writer.write(output_pdf_file)
                        print(f"解密后文件已保存为: {output_file}")
                        return True
                else:
                    print(f"密码'{password}'错误")
            except Exception as e:
                print(f"解密失败: {e}")
        else:
            print("该 PDF 文件没有加密。")
        return False

def generate_passwords(length):
    characters = string.ascii_letters + string.digits  # 字母加数字方式 可以添加其他字符
    for password in itertools.product(characters, repeat=length):
        yield ''.join(password)

if __name__ == "__main__":
    input_pdf_path = r"d:\"  # 输入你的加密 PDF 文件路径
    output_pdf_path = r"d:\"  # 输出解密后文件的路径

    # 尝试生成长度为1到4的所有可能的密码
    for length in range(1, 5):  # 可调整最大长度
        print(f"尝试长度为 {length} 的密码...")
        for password in generate_passwords(length):
            if decrypt_pdf(input_pdf_path, output_pdf_path, password):
                break
相关推荐
海带紫菜菠萝汤2 小时前
免费在线翻译器横评:2026年6款PDF翻译工具对比
人工智能·python·pdf
SunnyDays10112 小时前
C# 加密和解密 PDF:设置密码、AES 加密及操作权限
pdf·c#·加密 pdf·解除 pdf 密码·pdf 权限设置·pdf 文档安全
SamChan904 小时前
WebSocket实现PDF翻译进度实时推送:Go后端+React前端的完整方案
前端·websocket·pdf·c#·react·机器翻译
森叶1 天前
拆解 PDF 翻译引擎:表格纹丝不动、长语言自动缩放、图片文字 AI 重绘背后的工程
人工智能·pdf
AI创界者1 天前
MinerU v3.4.4 离线部署实战:PDF/PPT/图片一键转 Markdown,低至 4G 显存/纯 CPU 可用
pdf·powerpoint
cosinmz1 天前
图片转PDF:手机合同照片如何整理成规范PDF文件
pdf·pdf转换·图片转pdf·图片转pdf小程序
a1117761 天前
深入理解 AI Agent PDF(设计原理与工程实践 )
pdf
CCC65A8780D2C1 天前
PaddleOCR-VL-1.6图片PDF文档解析识别成文本工具,解压就能用,完全本地离线
pdf
桐桐桐1 天前
技术文档翻译实践:保留PDF表格与版式的几种方案
pdf·自动化
王莎莎-MinerU1 天前
别让 Agent 重读 PDF:文档解析要交付可缓存资产
网络·数据库·人工智能·驱动开发·缓存·pdf·ocr