[]
        
(Showing Draft Content)

Ink Annotation

An ink annotation represents a freehand scribble composed of one or more disjoint paths. When an ink annotation is opened, it displays a pop-up window containing the text of the related note. GcPdf provides InkAnnotation class to enable users to apply ink annotations to the PDF file.

image

InkAnnotation class provides the following properties to set various options for the ink annotation:

Property

Description

UserName

Adds the user name to the text label in the title bar of the annotation’s pop-up window when the annotation is open and active.

Subject

Adds the text representing the subject of the annotation.

Contents

Adds the text to the annotation for display.

RichText

Adds the text to the annotation for display in the pop-up window when opened. You can format this text using HTML tags.

Opacity

Sets the opacity of the annotation.

LineWidth

Sets the line width in points.

LineDashPattern

Sets the line dash pattern. Null means a solid line.

Color

Sets the annotation color, popup window color, line color, etc.

PdfRect

Sets the rectangle that defines the location and size of the annotation on a page in PDF user space coordinates. The positive X axis extends horizontally to the right, and the positive Y axis extends vertically upward, with the origin usually in the lower left corner of the page.

Paths

Sets the list of lists of points, in which each list of points represents a stroked path. The coordinates of points are relative to the upper left corner of the page's media box, with the Y (vertical) coordinates increasing from top to bottom.

Refer to the following example code to add an ink annotation to a PDF document:

public void CreateInkAnnotation()
{
    var doc = new GcPdfDocument();
    var page = doc.NewPage();
    RectangleF rc = new RectangleF(50, 50, 250, 50);
    page.Graphics.DrawString("This sample creates an ink annotation and shows how to use the " +
        "InkAnnotation.Paths property",
        new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc);

    //Create an instance of InkAnnotation class and set its relevant properties
    var inkAnnot = new InkAnnotation()
    {
        UserName = "Jaime Smith",
        PdfRect = new RectangleF(rc.Left, rc.Bottom + 20, 72 * 5, 72 * 2),
        LineWidth = 2,
        Color = Color.DarkBlue,
        Contents = "This is an ink annotation drawn via InkAnnotation.Paths."
    };
    float x = 80, y = rc.Bottom + 24, h = 18, dx = 2, dy = 4, dx2 = 4, w = 10, xoff = 15;

    // Scribble 'ink annotation' text:

    // i
    List<PointF[]> paths = new List<PointF[]>();
    paths.Add(new[] { new PointF(x + w / 2, y), new PointF(x + w / 2, y + h),
                       new PointF(x + w, y + h * .7f) });
    paths.Add(new[] { new PointF(x + w / 2, y), new PointF(x + w / 2, y + h),
                       new PointF(x + w, y + h * .7f) });
    paths.Add(new[] { new PointF(x + w / 2 - dx, y - h / 3 + dy),
                       new PointF(x + w / 2 + dx, y - h / 3) });
    // n
    x += xoff;
    paths.Add(new[] { new PointF(x, y), new PointF(x, y + h), new PointF(x, y + h - dy),
                       new PointF(x + w*0.7f, y),
    new PointF(x + w - dx/2, y + h*.6f), new PointF(x + w, y + h), new PointF(x + w + dx2, y + h*.7f) });
    // k
    x += xoff;
    paths.Add(new[] { new PointF(x, y - h / 3), new PointF(x, y + h) });
    paths.Add(new[] { new PointF(x + w, y), new PointF(x + dx, y + h/2 - dy), new PointF(x, y + h/2),
    new PointF(x + dx2, y + h/2 + dy), new PointF(x + w, y + h), new PointF(x + w + dx2, y + h*.7f) });
    inkAnnot.Paths = paths;

    page.Annotations.Add(inkAnnot);
    doc.Save("InkAnnotation.pdf");
}