// 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 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, a regular expressions is used
    // in the search string.
    public class FindAndSquiggly
        public int CreatePDF(Stream stream)
            // Load the PDF:
            var doc = new GcPdfDocument();
            using var 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:
            var ft = new FindTextParams("javascript\\s+framework", wholeWord: false, matchCase: false, regex: true);
            var found = doc.FindText(ft, null);

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

            // Done:
            return doc.Pages.Count;