Add Line Annotation
Contents
[
Hide
]
Line annotations are useful for emphasizing text, highlighting relationships, or drawing attention to specific areas in a PDF. With PdfContentEditor, you can programmatically create line annotations by specifying the start and end points, bounding rectangle, color, border style, and line endings.
- Create the PdfContentEditor object.
- Bind the input PDF.
- Define Line Annotation properties.
- Add the Line annotation.
- 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_line_annotation(infile, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind input PDF file
content_editor.bind_pdf(infile)
# Create LineAnnotation object
rect = apd.Rectangle(100, 100, 200, 200)
contents = "This is line annotation"
content_editor.create_line(
rect,
contents,
100,
100,
200,
200,
1,
1,
apd.Color.red,
"Solid",
[3, 2],
["Square"],
)
# Save output PDF file
content_editor.save(outfile)