'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) MESCIUS 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
Imports GrapeCity.Documents.Common

'' 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
                Dim area As List(Of Quadrilateral) = New List(Of Quadrilateral)
                For Each b In f.Bounds
                markup.Area = area

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