Can't find what you're looking for?

Contact us or post in our forums and we'll help you find an answer.

Using InkAnnotation to add free-hand text to a PDF in Documents for PDF

Background:

The InkAnnotation class can be used to add free-hand text to a PDF. The InkAnnotation.Paths property is used to render the annotation's content which is specified by discrete points that should be connected when a PDF viewer renders them. The points can be connected either by straight or curved lines depending on the viewer implementation.

Steps to Complete:

1. Create an InkAnnotation instance:

var inkAnnot = new InkAnnotation()

            {

                UserName = user1,

                Rect = 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;

 2. Scribble ‘ink’ text on the PDF:

            // i

            inkAnnot.Paths.Add(new[] { new PointF(x + w/2, y), new PointF(x + w/2, y + h), new PointF(x + w, y + h*.7f) });

            inkAnnot.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;

            inkAnnot.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;

            inkAnnot.Paths.Add(new[] { new PointF(x, y - h/3), new PointF(x, y + h) });

            inkAnnot.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) });

3. Add annotation to the Page

page.Annotations.Add(inkAnnot);

       where page is the Page class instance representing a page of the document.  

Get the Latest Version of Documents for PDF for .NET
Download the Free Trial Now