Here in the below pdf i have highlighted “is” in the first paragraph.
so is will be there in whole document but it should highlight in 1st paragraph only.
Inputs to the PDF are one is paragraph and other is markup text
forexample : markupPdf(paragraph, actualtext)
1st paragraph -
Adobe® Portable Document Format (PDF) is a universal file format that preserves all
of the fonts, formatting, colours and graphics of any source document, regardless of
the application and platform used to create it.
2nd actualText -
is
if actualtext is is present in multiple places in paragraph, do we have anything like sentences that takes exact match. means like inputs will be 3 -> paragraph, sentence, is
MarkupPdf.pdf (11.3 KB)
right now im using the following code where it takes inputtext and finds the text in whole document
var textFragmentCollection = TextFragmentCollection(parameters.InputText, pdfDocument);
if (textFragmentCollection.Count == 0)
{
return false;
}
foreach (var textFragment in textFragmentCollection)
{
var freeText = new HighlightAnnotation(textFragment.Page, textFragment.Rectangle)
{
Color = Color.FromRgb(System.Drawing.Color.Yellow),
Name = Properties.Resources.AnnotationName,
Title = Properties.Resources.AnnotationTitle,
Contents = parameters.InputText.Replace(Properties.Resources.Search, " "),
};
textFragment.Page.Annotations.Add(freeText);
}
private static TextFragmentCollection TextFragmentCollection(string inputText, Document document)
{
var text = inputText.Replace(" ", Properties.Resources.Search);
ParagraphAbsorber absorber = new ParagraphAbsorber();
absorber.Visit(document);
foreach (PageMarkup markup in absorber.PageMarkups)
{
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(text, new TextSearchOptions(true));
document.Pages.Accept(textFragmentAbsorber);
// var textFragmentAbsorber = new TextFragmentAbsorber(text, new TextSearchOptions(true));
//foreach (var page in document.Pages)
//{
// textFragmentAbsorber.Visit(page);
//}
//document.Pages.Accept(textFragmentAbsorber);
var count = textFragmentAbsorber.TextFragments.Count;
if (count > 0)
{
return textFragmentAbsorber.TextFragments;
}
}
var textFragmentAbsorberWithoutOptions = new TextFragmentAbsorber(inputText, new TextSearchOptions(false));
foreach (var page in document.Pages)
{
textFragmentAbsorberWithoutOptions.Visit(page);
}
//document.Pages.Accept(textFragmentAbsorberWithoutOptions);
return textFragmentAbsorberWithoutOptions.TextFragments;
}