Add Polyline Annotation

Contents
[ ]

Polyline annotations allow you to highlight a series of connected line segments in a PDF. Using PdfContentEditor, you can draw a polyline by specifying vertices coordinates, border style, page number, and annotation bounds. This is useful for visually representing paths, trends, or connections in diagrams and documents.

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

    line_info = pdf_facades.LineInfo()
    line_info.border_style = 0  # 0 - Solid
    line_info.vertice_coordinate = [120, 420, 180, 460, 230, 430, 290, 470]
    content_editor.create_poly_line(
        line_info,
        1,
        apd.Rectangle(110, 410, 200, 90),
        "This is polyline annotation",
    )

    # Save output PDF file
    content_editor.save(outfile)