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
相关推荐
SEO-狼术16 小时前
Infragistics now supports .NET 10
pdf·.net
琪伦的工具库18 小时前
批量PDF合并工具使用说明:批量合并与直接合并两种模式,拖拽排序/页面范围/遍历子目录/重名自动处理
数据结构·pdf·排序算法
琪伦的工具库18 小时前
批量PDF多页面合并工具使用说明:多页合并N合1/多文件合并,支持页码范围/矢量模式/DPI与布局边距
pdf
小贺儿开发2 天前
Unity3D 心理沙盘互动演示
unity·ai·pdf·人机交互·工具·互动·心理沙盘
私人珍藏库2 天前
[Windows] PDF工具箱 PDF24 Creator 11.30.0
windows·pdf·工具·软件·多功能
彭于晏Yan2 天前
基于iText7的动态PDF生成技术方案
spring boot·pdf
悟乙己2 天前
Advanced RAG 02:揭秘 PDF 解析
ai·pdf·llm·文档解析
lq12332102 天前
PDF工具箱 PDF24 Creator 11.30.0
pdf
忧郁的Mr.Li2 天前
JAVA工具类---PDF电子签章工具类
java·pdf
AscendKing3 天前
免费、易用、覆盖全平台的网页转 PDF 工具
pdf·html·网页保存·网页保存为pdf·保存网页位pdf