In the example code below, I search for the text "PRUDENTIAL AFFILIATE" in a regex form (to be highlighted in red) and plain-text form (to be highlighted in gold). When this is working correctly I would expect the two occurrences (only the upper case ones) to be highlighted in "orange" (being a combination of the red and gold highlighting). At present, the first is orange and the second is gold, indicating that it was not found by the Regex search.
This appears to be related to the internal structure of the PDF. If I recreate the document with the same text and perform the same text it behaves as expected. Unfortunately this isn't the only example I have of this happening though.
- Code: Select all
public void RegexSearchTest()
{
string strFileName = @"Prudential Short.pdf";
string strTargetName = @"Short Highlighted.pdf";
string strRegexSearch = @"PRUDENTIAL(\s{1,200})AFFILIATE"; //Plenty of whitespace to cross the line break and pre-text padding
string strOtherSearch = @"PRUDENTIAL AFFILIATE";
Spire.Pdf.PdfDocument pdf = new PdfDocument(strFileName);
foreach (PdfTextFind text in pdf.Pages[0].FindText(strRegexSearch, TextFindParameter.Regex).Finds)
{
text.ApplyHighLight(Color.Red);
}
foreach (PdfTextFind text in pdf.Pages[0].FindText(strOtherSearch, TextFindParameter.CrossLine).Finds)
{
text.ApplyHighLight(Color.Gold);
}
pdf.SaveToFile(strTargetName);
pdf.Close();
}