Iterating through characters in a text run

Q: I am having trouble iterating through characters in a text
element .
PDFTron CharIterator.Next() is throwing an error. This works for most
documents but not for this particular one. Can you tell me what might
be wrong with it? I am iterating similar to this code below:

ElementReader elementreader = new ElementReader();
Element element = null;
elementreader.Begin(page);

while ((element = elementreader.Next()) != null) {
if (element.GetType() == Element.ElementType.e_text) {
       CharIterator chItr = element.GetCharIterator();
       for (int k = 0; k < chArr.Length; ++k){
       char ch = chArr[k];
       chItr = chItr.Next(); // THIS FAILS ON SOME OF THE ELEMENTS
   }
}
-------
A: The problem is that chArr.Length (in the code adove) may not
necessarily correspond to the number of characters in a text run. In
PDF some characters may take more than one byte (analogous to Multi
Byte Character MBC encoding schemes). To fix the problem you should
check if the iterator is valid (as shown in ElementReaderAdv sample
project):

CharIterator chItr = element.CharBegin(); CharIterator chEnd =
element.CharEnd(); for (;chItr!=chEnd; chItr.Next()) { ...
}