添加折线注释

Contents
[ ]

折线注释允许您在 PDF 中突出显示一系列相连的线段。使用 PdfContentEditor,您可以通过指定顶点坐标、边框样式、页码和注释边界来绘制折线。这对在图表和文档中直观地表示路径、趋势或连接非常有用。

  1. 创建 PdfContentEditor 对象。
  2. 绑定输入 PDF。
  3. 配置 Polyline 属性。
  4. 添加 Polyline 注释。
  5. 保存已更新的 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)