@jameshale: I noticed the index problem when I was looking into the pageHeights/pageRanges issue when paragraph properties are applied. I had a go at fixing the problem but I was getting partial lines in the character ranges and I couldn't figure out what was going on in the time I had. The pageRanges code was based on the pageHeights code which is why they are probably showing similar issues.
I think we can agree that the correct behavior of pageRanges and pageHeights should be that you get sequences of pages that fit within the geometry of the field so I think that is the behavior to aim for. At the moment the routines are not taking into account paragraph properties that add space in-between paragraphs which is the principal problem I think.
Of course, that problem does illustrate a deficiency in pageRanges as a means to do pagination - if a page splits a paragraph half-way through its lines, what should happen if the paragraph has spacing above/below or borders? i.e.
Code: Select all
+----------+
|Some text |
|wrapped |
+----------+
If a page break occurs between these two lines, really the border / spacing should apply above the first line on the first page, and then below the second line on the second page. This is something what would mostly work with pageHeights (since the field should clip the unwanted sections away); however with pageRanges its a little more tricky as that's just giving you a character range (and so can't communicate any changes in formatting that might be needed).
Ultimately I guess what we need is both to be able to set things like borders individually (top, left, right, bottom) and then modifications to the styled text exporting properties (RTF, HTML, StyledText array) so that if you export part of a paragraph it appropriately unsets any non-applicable borders and such. (This is me musing slightly here - the pageHeights / pageRanges still at least need to be fixed to work as well as they can with current field properties).