Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Mar 24, 2023 12:44 pm

We have a problem with document that we attached to this issue. When we try to highlight whole word "is" code is preacking on line :
List<PdfTextFragment> result = finder.Find(word);
with error :Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'startIndex')[/b]
It is always happening on the same page 181. This page has 13 occurrences of word "is" and das not seam to have any problematic characters, and by that time we find more then 2000 occurrences of the word. On document containing only this page it is working without error. We tested document with other words like "and" and it was working well and occurrences of word that we find was more then 3000.
This is the part of the code that we use dictionary has only one word "is" for testing:

dictionary = dictionary.OrderByDescending(x => x.Length).ToList();
PdfUsedFont[] usedfont = doc.UsedFonts;
PdfBrush brush = new PdfSolidBrush(Color.Black);
replaceNum = 0;
PdfTextFindOptions findOptions = new PdfTextFindOptions();
findOptions.Parameter = TextFindParameter.WholeWord | TextFindParameter.IgnoreCase;

foreach (PdfPageBase page in doc.Pages)
{
foreach (string word in dictionary)
{

PdfTextFinder finder = new PdfTextFinder(page);
finder.Options = findOptions;
List<PdfTextFragment> result = finder.Find(word);
replaceNum = replaceNum + result.Count();
if (result.Count > 0)
{
foreach (PdfTextFragment findWord in result)
{
findWord.HighLight(colour);

}
}
}
}

If you need any other data please let me know.
Regards
Biljana.

bstojanovic
 
Posts: 41
Joined: Mon Sep 28, 2020 2:54 pm

Mon Mar 27, 2023 2:08 am

Hi Biljana,

Thanks for your feedback.
After testing, I reproduced your issue and logged it into our issue tracking system with the ticket number SPIREPDF-5891, our developers will investigate and fix it. Sorry for the inconvenience caused, once the issue is fixed, I will inform you asap.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Fri Apr 28, 2023 7:46 am

Hi,

Thanks for your patience.
Glad to inform you that we just release Spire.Office 8.4.1 hotfix, which has fixed your issue SPIREPDF-5891, please download the new version from the following links and have a test.
Website link: https://www.e-iceblue.com/Download/download-office-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.Office/8.4.1

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF