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

'' This sample loads the PDF file created by the BalancedColumns sample,
'' finds all occurrences of the words 'lorem' and 'ipsum' in the loaded document,
'' and highlights these two words using different colors.
Public Class FindText
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()

        '' The original file stream must be kept open while working with the loaded PDF, see LoadPDF for details:
        Using fs = New FileStream(Path.Combine("Resources", "PDFs", "BalancedColumns.pdf"), FileMode.Open, FileAccess.Read)
            '' Find all 'lorem', using case-insensitive word search:
            Dim findsLorem = doc.FindText(
                New FindTextParams("lorem", True, False),
            '' Ditto for 'ipsum':
            Dim findsIpsum = doc.FindText(
                New FindTextParams("ipsum", True, False),
            '' Highlight all 'lorem' using semi-transparent orange red:
            For Each find In findsLorem
                doc.Pages(find.PageIndex).Graphics.FillPolygon(find.Bounds, Color.FromArgb(100, Color.OrangeRed))
            '' Put a violet red border around all 'ipsum':
            For Each find In findsIpsum
                doc.Pages(find.PageIndex).Graphics.DrawPolygon(find.Bounds, Color.MediumVioletRed)
            '' Done:
        End Using
        Return doc.Pages.Count
    End Function
End Class