AddCaretAnnotation.vb
C# VB
'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports System.IOImports System.DrawingImports GrapeCity.Documents.PdfImports GrapeCity.Documents.Pdf.Annotations
'' This example shows how to create a caret annotation used to indicate a specific position in a text.Public Class AddCaretAnnotation Public Function CreatePDF(ByVal stream As Stream) As Integer Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "Wetlands.pdf")) Dim doc = New GcPdfDocument() doc.Load(fs)
For Each page In doc.Pages Dim tm = page.GetTextMap() ' insert the CaretAnnotation after "The Importance" text tm.FindText(New FindTextParams("wetlands", False, False), Sub(fp_) ' Add a CaretAnnotation near the found text: Dim r = fp_.Bounds(0).ToRect() Dim ca = New CaretAnnotation() With { .Page = page, .Rect = New RectangleF(r.Left - 8, r.Bottom - 16, 16, 16) } End Sub) Next ' Done: doc.Save(stream) Return doc.Pages.Count End Using End FunctionEnd Class