使用 Python 管理 PDF 中的註釋

管理 PDF 文件中的註釋。在 Python for .NET 中使用 Aspose.PDF 以編程方式修改 PDF 文件

Aspose.PDF for Python for .NET Logo

如何使用 Python 程式庫管理註釋

為了在 PDF 文件中添加文本註釋,我們將使用 Aspose.PDF for .NETAPI,該 API 是 python-net 平台的功能豐富,功能強大且易於使用的文檔操作 API。打開 NuGet軟件包管理器,搜索 ** Aspose.pdf** 並安裝。您也可以使用套件管理員主控台中的下列命令。

Console

pip install aspose-pdf

通過 Python 在 PDF 文件中創建註釋


您需要 Aspose.PDF for Python via .NET來嘗試您的環境中的代碼。

1.在文件類別的執行個體中載入 PDF。 1.建立您要新增至 PDF 的註解。 1.將註釋加入到「頁面」物件的「註釋」集合中。 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)