How do I get a height (size) of a text element?


I need the height of a text element. By calling:

GState gs = elemet.GetGState ();
int db = gs.GetFontSize ();

I don't get the correct height in all PDF documents. For some
documents I receive '1' as value for all elements. How do I get a
height of a text element?


If you want to get the font size as it appears on the page you need to
scale GetFontSize() with text matrix (Element.GetTextMatrix()) , as
well as, current transformation matrix (CTM):

double scale_factor = Math.sqrt(mtx.m_b*mtx.m_b + mtx.m_d*mtx.m_d);
double page_font_sz = gs.GetFontSize() * scale_factor;

Please see:

You can also use element.GetBBox() to obtain a non-tight bounding box
for the entire text run (i.e. element). The resulting rectangle lies
in PDF user space (i.e. PDF page coordinate system).

In case you need to obtain the tight bounding box for each character
in the text run please see the following KB article:

  or search for 'minimum bounding box for each character' in