使用 Python 管理 PDF 中的批注

管理 PDF 文档中的注释。使用 Aspose.PDF for Python for .NET 以编程方式修改 PDF 文件

Aspose.PDF for Python for .NET Logo

如何使用 Python 库管理注释

为了在 PDF 文件中添加文本注释,我们将使用 Aspose.PDF for .NET API,这是一款功能丰富、功能强大且易于使用的文档操作 API,适用于 python-net 平台。打开 NuGet 软件包管理器,搜索 Aspose.PDF 并安装。您也可以使用包管理器控制台中的以下命令。

Console

pip install aspose-pdf

通过 Python 在 PDF 文档中创建注释


你需要 通过.NET for Python 的 Aspose.PDF 才能在你的环境中试用代码。

1。在 Document 类的实例中加载 PDF。 1。创建要添加到 PDF 的注释。 1。将注释添加到 Page 对象的注释集合中。 1。保存 PDF 文件。

PDF 文本注释-Python

Example: Python

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

document = apdf.Document(path_infile)

appearance = apdf.annotations.DefaultAppearance()
appearance.font_size = 12
appearance.font_name = "Arial"

freeTextAnnotation = apdf.annotations.FreeTextAnnotation(
    document.pages[1],
    apdf.Rectangle(299.988, 703.664, 508.708, 720.769, True),
    appearance
)
freeTextAnnotation.contents = "This is a free text annotation."
freeTextAnnotation.name = "FreeText1"
freeTextAnnotation.subject = "Revision 01"
freeTextAnnotation.title = "Free Text Annotation"
freeTextAnnotation.popup = apdf.annotations.PopupAnnotation(
    document.pages[1], apdf.Rectangle(299.988, 713.664, 308.708, 720.769, True)
)
freeTextAnnotation.popup.open = True
document.pages[1].annotations.add(freeTextAnnotation, consider_rotation=False)
document.save(path_outfile)