Add Free Text Annotations

Contents
[ ]

Free text annotations allow you to place visible text directly onto a PDF page without requiring pop-up comments. Using PdfContentEditor, you can specify the annotation rectangle, the displayed text, and the target page.

  1. Create the PdfContentEditor object.
  2. Bind the input PDF.
  3. Define the Annotation position.
  4. Add the Free Text Annotation.
  5. Save the updated Document.
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades
import aspose.pydrawing as apd
import sys
from os import path

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir


def add_free_text_annotation(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Add free text annotation to page 1
    content_editor.create_free_text(
        apd.Rectangle(200, 480, 150, 25), "This is a free text annotation", 1
    )
    # Save updated document
    content_editor.save(outfile)