InkAnnotPaths.vb
''
'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.Annotations
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing

'' Shows how to add an ink annotation to a PDF document,
'' and how to render its content using the InkAnnotation.Paths property.
Public Class InkAnnotPaths
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()
        '' User name for the annotation's author:
        Dim user1 = "Jaime Smith"

        Dim rc = Util.AddNote(
                "This sample creates an ink annotation and shows how to use the InkAnnotation.Paths property " +
                "to render the annotation's content. The content 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.",
                page)

        Dim inkAnnot = New InkAnnotation() With
            {
                .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."
            }
        Dim x0 = 80, x = 80, y = rc.Bottom + 24, h = 18, dx = 2, dy = 4, dx2 = 4, w = 10, xoff = 15

        '' Scribble 'ink annotation' text:

        '' i
        Dim paths As List(Of PointF()) = New List(Of PointF())
        paths.Add({New PointF(x + w / 2, y), New PointF(x + w / 2, y + h), New PointF(x + w, y + h * 0.7F)})
        paths.Add({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 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 * 0.6F), New PointF(x + w, y + h), New PointF(x + w + dx2, y + h * 0.7F)})
        '' k
        x += xoff
        paths.Add({New PointF(x, y - h / 3), New PointF(x, y + h)})
        paths.Add({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 * 0.7F)})

        '' a
        x += xoff * 2
        paths.Add({New PointF(x + w, y + dy), New PointF(x + w / 2, y), New PointF(x, y + h / 2), New PointF(x + w / 2, y + h),
                New PointF(x + w, y + dy), New PointF(x + w, y), New PointF(x + w, y + h), New PointF(x + w + dx2, y + h * 0.7F)})
        '' n
        x += xoff
        paths.Add({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 * 0.6F), New PointF(x + w, y + h), New PointF(x + w + dx2, y + h * 0.7F)})
        '' n
        x += xoff
        paths.Add({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 * 0.6F), New PointF(x + w, y + h), New PointF(x + w + dx2, y + h * 0.7F)})
        '' o
        x += xoff
        paths.Add({New PointF(x + w / 2, y), New PointF(x + w / 2 - dx, y), New PointF(x, y + h / 2), New PointF(x + w / 2, y + h),
                New PointF(x + w, y + h / 2), New PointF(x + w / 2 + dx, y), New PointF(x + w / 2, y)})
        '' t
        x += xoff
        paths.Add({New PointF(x + w / 2, y - h / 3), New PointF(x + w / 2, y + h), New PointF(x + w, y + h * 0.7F)})
        paths.Add({New PointF(x, y), New PointF(x + w, y)})
        '' a
        x += xoff
        paths.Add({New PointF(x + w, y + dy), New PointF(x + w / 2, y), New PointF(x, y + h / 2), New PointF(x + w / 2, y + h),
                New PointF(x + w, y + dy), New PointF(x + w, y), New PointF(x + w, y + h), New PointF(x + w + dx2, y + h * 0.7F)})
        '' t
        x += xoff
        paths.Add({New PointF(x + w / 2, y - h / 3), New PointF(x + w / 2, y + h), New PointF(x + w, y + h * 0.7F)})
        paths.Add({New PointF(x, y), New PointF(x + w, y)})
        '' i
        x += xoff
        paths.Add({New PointF(x + w / 2, y), New PointF(x + w / 2, y + h), New PointF(x + w, y + h * 0.7F)})
        paths.Add({New PointF(x + w / 2 - dx, y - h / 3 + dy), New PointF(x + w / 2 + dx, y - h / 3)})
        '' o
        x += xoff
        paths.Add({New PointF(x + w / 2, y), New PointF(x + w / 2 - dx, y), New PointF(x, y + h / 2),
                New PointF(x + w / 2, y + h), New PointF(x + w, y + h / 2), New PointF(x + w / 2 + dx, y), New PointF(x + w / 2, y)})
        '' n
        x += xoff
        paths.Add({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 * 0.6F), New PointF(x + w, y + h), New PointF(x + w + dx2, y + h * 0.7F),
                New PointF(x + w * 3, y + h * 0.4F), New PointF(x + w + dx2, y + h + dy * 2), New PointF(x0, y + h + dy)})
        inkAnnot.Paths = paths

        page.Annotations.Add(inkAnnot)

        '' Done:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class