Add Square Annotation

Contents
[ ]

Square annotations are commonly used to highlight areas of interest, mark important sections, or provide visual cues in a PDF document. Using PdfContentEditor, you can create square (or circular) annotations by specifying the bounding rectangle, content text, border color, fill option, page number, and border width.

  1. Create the PdfContentEditor object.
  2. Bind the input PDF.
  3. Define the Square annotation.
  4. Add the Square 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_square_annotation(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind input PDF file
    content_editor.bind_pdf(infile)

    # Create SquareAnnotation object
    rect = apd.Rectangle(100, 300, 200, 400)
    contents = "This is square annotation"
    content_editor.create_square_circle(rect, contents, apd.Color.blue, True, 1, 3)

    # Save output PDF file
    content_editor.save(outfile)