Skip to main content
Inspiring
October 15, 2014
Answered

How to ignore notes when calling GetWordCountInfo?

  • October 15, 2014
  • 1 reply
  • 451 views

I'm using ITextUtils::GetWordCountInfo, works great except when there are notes. What do I have to do to ignore counting notes?

Thanks!

This topic has been closed for replies.
Correct answer -Rozi-

How about this:

  1. Get main story thread first.
  2. Determine its bounds: ITextStoryThread::GetTextStart() should return 0 and ITextStoryThread::GetTextEnd() should return end index of the main thread.
  3. Call ITextUtils::GetWordCountInfo() with startIndex and lengthToCount parameters set to match main thread section within the story.

This should count the number of words in main thread. It shouldn't count words in headers, footers and notes, as they are stored withing separarate threads. Table cell text is also stored in separate threads, thus you should probably iterate over those threads too and count their words.

1 reply

-Rozi-Correct answer
Inspiring
October 16, 2014

How about this:

  1. Get main story thread first.
  2. Determine its bounds: ITextStoryThread::GetTextStart() should return 0 and ITextStoryThread::GetTextEnd() should return end index of the main thread.
  3. Call ITextUtils::GetWordCountInfo() with startIndex and lengthToCount parameters set to match main thread section within the story.

This should count the number of words in main thread. It shouldn't count words in headers, footers and notes, as they are stored withing separarate threads. Table cell text is also stored in separate threads, thus you should probably iterate over those threads too and count their words.

Inspiring
October 16, 2014

Great, thanks! I just used ITextModel::QueryStoryThread with a position of 0 to get the primary thread.