FindAndUnderline.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 System.Collections.GenericImports GrapeCity.Documents.PdfImports GrapeCity.Documents.Pdf.AnnotationsImports GrapeCity.Documents.Common
Public Class FindAndUnderline Public Function CreatePDF(ByVal stream As Stream) As Integer ' Load the PDF: Dim doc = New GcPdfDocument() Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "The-Rich-History-of-JavaScript.pdf")) doc.Load(fs)
' Find all occurrences of "JavaScript" or "ECMAScript" using regex: Dim ft = New FindTextParams("JavaScript|ECMAScript", wholeWord:=False, matchCase:=False, regex:=True) Dim found = doc.FindText(ft, Nothing)
' Add a text markup annotation to underline each occurrence: For Each f In found Dim markup = New TextMarkupAnnotation() With { .Page = doc.Pages(f.PageIndex), .MarkupType = TextMarkupType.Underline, .Color = Color.Red } Dim area As New List(Of Quadrilateral) For Each b In f.Bounds area.Add(b) Next markup.Area = area Next
' Done: doc.Save(stream) Return doc.Pages.Count End Using End FunctionEnd Class