Aspose.Pdf.Examples.CSharp.AsposePDF.Text.SearchTextAndDrawRectangle.Run C# (CSharp) Method

Run() public static method

public static Run ( ) : void
return void
        public static void Run()
        {
            // ExStart:SearchTextAndDrawRectangle
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            // Open document
            Document document = new Document(dataDir + "SearchAndGetTextFromAll.pdf");

            // Create TextAbsorber object to find all the phrases matching the regular expression

            TextFragmentAbsorber textAbsorber = new TextFragmentAbsorber(@"[\S]+");

            TextSearchOptions textSearchOptions = new TextSearchOptions(true);

            textAbsorber.TextSearchOptions = textSearchOptions;

            document.Pages.Accept(textAbsorber); 

            var editor = new PdfContentEditor(document); 

            foreach (TextFragment textFragment in textAbsorber.TextFragments)

            {

                foreach (TextSegment textSegment in textFragment.Segments)

                {

                        DrawBox(editor, textFragment.Page.Number, textSegment, System.Drawing.Color.Red);

                }

            }
            dataDir = dataDir + "SearchTextAndDrawRectangle_out.pdf";
            document.Save(dataDir);
            // ExEnd:SearchTextAndDrawRectangle
            Console.WriteLine("\nRectangle drawn successfully on searched text.\nFile saved at " + dataDir);
        }
        // ExStart:DrawBox
SearchTextAndDrawRectangle