Add Caret Annotation

Contents
[ ]

Caret annotations are commonly used to indicate text insertions or editorial comments in a document. With PdfContentEditor, you can programmatically add caret annotations by specifying the page number, annotation bounds, callout area, symbol, note text, and color.

  1. Create the PdfContentEditor object.
  2. Bind the input PDF.
  3. Define Caret Annotation parameters:
  • Page number where annotation will be added
  • Caret rectangle (annotation position)
  • Callout rectangle (text area)
  • Symbol (for example “P”)
  • Annotation text
  • Annotation color
  1. Add the Caret Annotation.
  2. 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_caret_annotation(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Add caret annotation to page 1
    content_editor.create_caret(
        1,
        apd.Rectangle(350, 400, 10, 10),
        apd.Rectangle(300, 380, 115, 15),
        "P",
        "This is a caret annotation",
        apd.Color.red,
    )
    # Save updated document
    content_editor.save(outfile)