小编n33*_*n33的帖子

如何在Python 3中删除pdf中的注释

我最初的目标是删除 PDF 页面上大量的白边。

然后我发现使用下面的代码缩放页面就可以达到这个目的,但是注释没有缩放。

import PyPDF2

# This works fine
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)

# This attempts to remove annotations
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'])
Run Code Online (Sandbox Code Playgroud)

有没有办法去掉注释?或者任何可以帮助我摆脱白边的建议。

python pypdf python-3.x

6
推荐指数
1
解决办法
3770
查看次数

标签 统计

pypdf ×1

python ×1

python-3.x ×1