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
相关推荐
web打印社区7 小时前
前端开发实现PDF打印需求:从基础方案到专业解决方案
前端·vue.js·react.js·electron·pdf
Kratzdisteln8 小时前
【MCM】(x= (N_A),y=(N_G),z=(p))RGB=T*
pdf
Kratzdisteln9 小时前
【1902】process_assignment_pdf()
大数据·人工智能·pdf
AAA_搬砖达人小郝12 小时前
Markdown 一键生成完美 Word(.docx) + PDF 的完整实战方案(JDK 8 环境亲测可用)
pdf·word
Kratzdisteln1 天前
【1902】process_handout_pdf()
服务器·windows·pdf
星月前端1 天前
springboot中使用LibreOffice实现word转pdf(还原程度很高,可以配置线程并发!)
spring boot·pdf·word
qq_171520351 天前
linux服务器springboot(docker)项目word转pdf中文乱码
linux·spring boot·docker·pdf·word
100分简历2 天前
无图标简洁大方的简历模板下载
人工智能·面试·职场和发展·pdf·编辑器
zyplayer-doc2 天前
文档增加访问密码设置,编辑器增加导航,登录日志增加IP归属地和浏览器信息展示,zyplayer-doc 2.5.9 发布啦!
人工智能·pdf·编辑器·飞书·开源软件·有道云笔记
appearappear2 天前
wkhtmltopdf把 html 原生转成成 pdf
前端·pdf·html