'' This code is part of GrapeCity Documents for PDF samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
Imports System
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Pdf.Annotations

'' This example shows how to find all occurrences of a phrase in a PDF document and
'' highlight all those occurrences using the text markup squiggly underline annotation.
'' To ensure that all occurrences of the phrase ("javascript framework") are found
'' even if the words are separated by a line break, regular expressions are turned
'' on in the search.
Public Class FindAndSquiggly
    Public Function CreatePDF(stream As Stream) As Integer
        ' Load an existing PDF:
        Dim doc As New GcPdfDocument()
        Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "CompleteJavaScriptBook.pdf"))

            ' Find all occurrences of the phrase "javascript framework" using regex so that
            ' words separated by line breaks are found:
            Dim ft As New FindTextParams("javascript\s+framework", False, False, , , , True)
            Dim found = doc.FindText(ft, Nothing)

            ' Add a text markup annotation to wavy underline each occurrence:
            For Each f In found
                Dim markup As New TextMarkupAnnotation() With {
                        .Page = doc.Pages(f.PageIndex),
                        .MarkupType = TextMarkupType.Squiggly,
                        .Color = Color.Magenta
                For Each b In f.Bounds

            ' Done:
            Return doc.Pages.Count
        End Using
    End Function
End Class