Skip to main content
Inspiring
March 30, 2017
Answered

Counting line in paragraph

  • March 30, 2017
  • 1 reply
  • 1282 views

Hello,

I usually work with structured FM doc, but for once i need to work with unstructured doc.

I need to make a script that check if there is only few chararter at the last line of a paragraph, and if yes, to apply a "spread -2%". and check if i lost one line.

I was thinking, if i can compare the number of line of a paragraph before and after the "spread -2%" and if it's "after" is smaller than "before".

If yes => i lost one line in my paragraph.

In million paragaph, i can win few pages in my doc (doc large than 1.000 pages)

I already have script to walkthrouth all the paragraph of a doc, another to apply and/or check paragraph values (spread).

But how can i count the number of line in one paragraph?

Do i have to put my cursor in each line of my paragraph and check the FTI_LineEnd (normal, hard, hyphen) to know when i reach the end of my paragraph? Or there is another way?

This topic has been closed for replies.
Correct answer Russ Ward

After posting that, I thought of this, which seems to do the same thing:

var ti = pgf.GetText(Constants.FTI_LineEnd);

If it requires less memory and/or processing, that might be better. I don't know if it does or not.

Russ

1 reply

Legend
March 31, 2017

Hi philippep2776167,

I think the easiest way to count lines in a paragraph is to retrieve the text items, then just look at the length of the array. For example:

var ti = pgf.GetText(Constants.FTI_String);

The length of "ti" will be the number of lines in the paragraph. For example, if the paragraph is 5 lines long, then:

ti.len == 5

Russ

Russ WardCorrect answer
Legend
March 31, 2017

After posting that, I thought of this, which seems to do the same thing:

var ti = pgf.GetText(Constants.FTI_LineEnd);

If it requires less memory and/or processing, that might be better. I don't know if it does or not.

Russ

4everJang
Legend
March 31, 2017

Hi Russ (and Philippe)

The array of strings may in fact have more elements than the number of lines. I cannot give you precise examples for unstructured text, but I did see them. The search for LineEnd is safer.

Ciao

Jang