Page 1 of 1

how to get the Height of a table ?

PostPosted: Tue Oct 13, 2009 3:32 pm
by dqkit
Hi all.
Any ideas about getting the height of a table?
mostly,we could get the height of a tr:
<w:trPr>
<w:trHeight w:val="699"/>
</w:trPr>

and we could add all the height of the TRs.
but..but,when there is too much text in an cell, the text would be placed into many rows. what now? how to get the height of the TR ?
Apreciate for any ideas.

Re: how to get the Height of a table ?

PostPosted: Wed Oct 14, 2009 12:05 am
by jason
dqkit wrote:but..but,when there is too much text in an cell, the text would be placed into many rows


Yes, you'd need a model of how many lines the text would be rendered in, and for that - depending how well you need to do it - you may need to deal with glyph sizes, kerning tables, and ligature information.

docx4j doesn't have anything like this right now.

It would be an interesting feature; and ultimately would help people who want to calculate page numbers.

You could use Java 2D's TextLayout. Search for 'LineBreakMeasurer'. I'm not sure whether this would be the best way - it might not handle hyphenation for example. There are other layout engines you could look at, including FOP, ICU.

May I ask why you need to know the table height?

Re: how to get the Height of a table ?

PostPosted: Wed Oct 14, 2009 8:04 am
by dqkit
thanks,jason.
May I ask why you need to know the table height?

you know that,
help people who want to calculate page numbers

that is exactly what I doing !

Re: how to get the Height of a table ?

PostPosted: Thu Oct 15, 2009 1:32 am
by jason
ok, i'll be interested to learn how you go.

maybe a method

Code: Select all
public int getHeight(P p, int availableWidth, int spaceAfterPrecedingParagraph)


which returns height in twips would work nicely, both for paragraphs in the body, and paragraphs in a td.

The arg spaceAfterPrecedingParagraph is necessary, because Word uses as the actual space to be inserted before a paragraph: the greater of this paragraph's space before, and the preceding paragraph's space after.

Re: how to get the Height of a table ?

PostPosted: Thu Oct 29, 2009 2:01 am
by jason
Please note the new structure package, and in particular, DocumentModel class. Right now, it doesn't deal with the document at this level of detail, but you could imagine a class associated with each w:tbl, and each org.docx4j.wml.P (paragraph) class, which can know the vertical space that object will occupy on the page). Ultimately, this would give you a page count.

Re: how to get the Height of a table ?

PostPosted: Thu Oct 29, 2009 10:29 am
by dqkit
thanks.
I am still doing with counting the pages... ;)
Are there anybody doing like that?