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
相关推荐
dagouaofei17 小时前
全面整理6款文档生成PPT工具,PDF转PPT不再难
python·pdf·powerpoint
yesyesyoucan17 小时前
PDF全能处理站:压缩、拆分、合并一站式解决方案与核心技术解析
pdf
sunon_19 小时前
解决linux系统PDF中文乱码问题
linux·运维·pdf
小灰灰搞电子20 小时前
Qt PDF模块详解
数据库·qt·pdf
TextIn智能文档云平台20 小时前
如何将公司内部知识库(Word/PDF)接入大模型?
pdf·word
HSJ017021 小时前
PDF专业转换工具 - 专业版V0.1,PDF转图片、拆分、合并,高效稳定可靠,永久免费使用
pdf
dagouaofei1 天前
文档生成PPT到底快不快?PDF转PPT工具实测分析
python·pdf·powerpoint
轻竹办公PPT2 天前
上传PDF直接生成PPT,适合工作汇报和总结场景
python·pdf·powerpoint
非凡ghost2 天前
FlexiPDF(专业PDF编辑软件)
windows·学习·pdf·软件需求
xinyu_Jina2 天前
PaperStudio:WYSIWYG文档的Web实现——从CSS Print到客户端PDF生成的技术解析
前端·css·pdf