Get AcroField PDF Text Height

Is there a way to calculate text height in AcroField?

In other words, I have a PDF template with a body section into which I want to insert my long text and want to get the height of the text. If it overflows, insert a new page for the rest of the text.

+4
source share
2 answers

This will give the height and width:

Vector curBaseline = renderInfo.GetBaseline().GetStartPoint(); Vector topRight = renderInfo.GetAscentLine().GetEndPoint(); iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle( curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2] ); Single curFontSize = rect.Height; 
+1
source

Just set the font size to zero for your field. This will automatically change the font so that the given text fits into your field ... within certain limits. I do not think that it will fall below 6 points.

Another alternative would be to use ColumnText and call myColText.go(true) . This will "mimic" the layout, letting you know what happens where you don't draw PDFs. Just pick up a column with the same size, font, and font as the field, and your results should be the same.

In fact, I believe that the iText text field rendering code uses ColumnText internally. Yes, look at the source of TextField.getAppearance() .

Please note that the bounding box of your field does not correspond to the field in which the text is laid out ... you need to consider the style and thickness of the drill. That is why I suggest you look at the source.

0
source

All Articles