如何在Python 3中删除PDF中的批注

14 浏览
0 Comments

如何在Python 3中删除PDF中的批注

我的原始目标是去除PDF页面上的大量白边。

然后我发现可以通过使用下面的代码来缩放页面来实现这个目的,但注释并没有被缩放。

import PyPDF2
# 这段代码运行正常
with open('old.pdf', 'rb') as pdf_obj:
    pdf = PyPDF2.PdfFileReader(pdf_obj)
    out = PyPDF2.PdfFileWriter()
    for page in pdf.pages:
        page.scale(2, 2)
        out.addPage(page)
    with open('new.pdf', 'wb') as f: 
        out.write(f)
# 这段代码试图删除注释
with open('old.pdf', 'rb') as pdf_obj:
    pdf = PyPDF2.PdfFileReader(pdf_obj)
    page = pdf.pages[2]
    print(page['/Annots'], '\n\n\n\n')
    page.Annots = []
    print(page['/Annots'])

有办法删除注释吗?或者有什么建议可以帮助我去掉白边。

0