用python加密PDF [英] Encrypt PDFs in python

查看:64
本文介绍了用python加密PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能和方法来用python加密PDF文件?一种可能是压缩PDF,但是还有另一种吗?谢谢你的帮助问候费利克斯

Is there a possible and way to encrypt PDF-Files in python? One possibility is to zip the PDFs but is there another ? Thanks for your help regards Felix

推荐答案

您可以使用 PyPDF2 :从pyPDF2中的

You can use PyPDF2:

from pyPDF2 import PdfFileReader, PdfFileWriter
with open("input.pdf", "rb") as in_file:
    input_pdf = PdfFileReader(in_file)

output_pdf = PdfFileWriter()
output_pdf.appendPagesFromReader(input_pdf)
output_pdf.encrypt("password")

with open("output.pdf", "wb") as out_file:
        output_pdf.write(out_file)

有关更多信息,请查看 PdfFileWriter 文档.

For more information, check out the PdfFileWriter docs.

这篇关于用python加密PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆