Manage Annotations in PDF via Python

Managing annotations in PDF document. Use Aspose.PDF for Python for .NET to modify PDF files programmatically

How to Manage Annotations Using Python for .NET Library

In order to add Text Annotation in PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for python-net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Python Package Manager Console

pip install aspose-pdf

Create Annotations in PDF document via Python

You need Aspose.PDF for Python to try the code in your environment.

  1. Load PDF in an instance of Document class.
  2. Create an annotation that you want to add to the PDF.
  3. Add the annotation to the Page object’s Annotations collection.
  4. Save the PDF file.

PDF Text Annotation - 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