[]
        
(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. DsPdf provides InkAnnotation class to enable users to apply ink annotations to the PDF file.

DsPdf demonstrating how to add ink annotation in a PDF document

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");
}