TextMatchGroup.Fragment Property
Obtains the text fragment that contains the found text part.
Namespace: DevExpress.Docs.Pdf
Assembly: DevExpress.Docs.Pdf.v26.1.dll
Declaration
Property Value
| Type | Description |
|---|---|
| TextFragment | The text fragment that contains the found text part. |
Example
How to: Format Found Text in a PDF Document
The following code snippet changes the font color of matching text fragments:
using DevExpress.Docs.Pdf;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using (FileStream fileStream =
File.OpenRead(@"Document.pdf"))
{
using (PdfDocument pdfDocument =
new PdfDocument(fileStream))
{
IEnumerable<TextSearchInfo> results =
pdfDocument.FindText("DevExpress",
new TextSearchOptions(true, true), 0, 2);
foreach (TextSearchInfo searchResult in results)
{
foreach (var group in searchResult.Groups)
{
// Split the fragment into matched parts.
var newFragments = group.Fragment
.Split(group,
out TextFragment[] matched,
out TextFragment[] notMatched);
// Apply formatting to matched fragments.
foreach (var matchedFragment in matched)
{
matchedFragment.Font =
new TextFont("Arial", TextFontStyle.Bold);
matchedFragment.ForegroundFill = new SolidFill(PdfColor.Red);
}
pdfDocument.Pages[searchResult.PageIndex]
.Fragments.Replace(
group.Fragment, newFragments);
}
}
pdfDocument.Save(new FileStream(
"Result.pdf", FileMode.Create,
FileAccess.Write));
}
}
See Also