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

namespace GcPdfWeb.Samples
    // This example shows how to find all occurrences of a word in a PDF document
    // and highlight all those occurrences using the text markup highlight annotation.
    // This example creates a text markup annotation per occurrence. A different approach
    // illustrated in MarkupPerPage is to create a text markup annotation per page.
    // The PDF used in this example was downloaded from
    public class FindAndHighlight
        public int CreatePDF(Stream stream)
            // Load the PDF:
            var doc = new GcPdfDocument();
            using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "fendo-13-1005722.pdf"));

            // Find all occurrences of the word "childbirths":
            var found = doc.FindText(new FindTextParams("childbirths", true, false), null);

            // Add a text markup annotation to highlight each occurrence:
            foreach (var f in found)
                var markup = new TextMarkupAnnotation()
                    Page = doc.Pages[f.PageIndex],
                    MarkupType = TextMarkupType.Highlight,
                    Color = Color.Yellow
                foreach (var b in f.Bounds)

            // Done:
            return doc.Pages.Count;