使用Python管理 PDF 中的批注

現代 Python 庫,用於使用我們的 API 管理 PDF 註釋。

如何使用 Python for .NET 庫管理批注

為了在PDF檔中添加文本註釋,我們將使用[Aspose.PDF for Python](https://products.aspose.com/pdf/net)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於 python-net 平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

Python Package Manager Console

pip install aspose-pdf

通過Python在 PDF 文件中創建批注


您需要 [Aspose.PDF for Python](https://releases.aspose.com/pdf/net)來嘗試環境中的代碼。

  1. 在文件類的實例中載入 PDF。
  2. 建立要添加到 PDF 中的批注。
  3. 將批註添加到 Page 物件的批注集合中。
  4. 保存 PDF 檔。

PDF 文本註釋 - Python

Example: Python

    def text_annotation_add(self, infile, outfile):

        path_infile = self.dataDir + infile
        path_outfile = self.dataDir + outfile

        pdfDocument = Document(path_infile)

        textAnnotation = TextAnnotation(pdfDocument.Pages[1], Rectangle(299.988, 713.664, 308.708, 720.769))
        textAnnotation.Title = "Aspose User"
        textAnnotation.Subject = "Inserted text 1"
        textAnnotation.Flags = AnnotationFlags.Print
        textAnnotation.Color = Color.Blue

        pdfDocument.Pages[1].Annotations.Add(textAnnotation)
        pdfDocument.Save(path_outfile)