How to read dynamic height of FloatingBox/paragraph/table?

I have two floating boxes with user defined text pulled from a database in each .

I want them both to be the same height

The boxes do grow in height to cater for whatever text is entered in them, but there doesn't seem to be a way to read what height it will be when rendered. Am I missing somthing?

Hi,

Please try using the BoxHeight property of FloatingBox class, which offers the capability to Get or Set a float value that indicates the height of the floating box.

In case it does not satisfy your requirement or you've any further query, please feel free to contact.

Hi,

I'd tried that but it just returns whatever was set when the FloatingBox was created. If the text in the box causes the height to grow beyond that then there doesn't seem to be a way of determining the new height

Do you have any other suggestions? If not then I'm sure I can code a workaround for it for my purposes.

Duane

Hi,

Sorry for replying you so late.

You can get text height using GetTextHeight() method of Text class, but there is one limitation for this method to return the correct height. First you need to set the Text width equal to the width of FloatingBox then you can call the method to return the TextHeight. Please try using the following code snippet in which some text is entered in FloatingBox1 and we’ve used the height of text in FloatingBox1 to be used as Height of FloatingBox2.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please try using the following code snippet and incase it does not satisfy your requirement or you’ve any further query, please feel free to contact.

[C#]

Pdf pdf1 = new Pdf();
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();

FloatingBox box1 = new FloatingBox(108, 80);
sec1.Paragraphs.Add(box1);
box1.BoxHorizontalPositioning = BoxHorizontalPositioningType.Margin;
box1.BoxHorizontalAlignment = BoxHorizontalAlignmentType.Left;
box1.BoxVerticalPositioning = BoxVerticalPositioningType.Page;
box1.BoxVerticalAlignment = BoxVerticalAlignmentType.Top;
Text text = new Text("Hello World !.... this is a new line sample #$NLsimple new line #$NL and this is another line");
//set the text.TextWidth first according to the FloatingBox width
text.TextWidth = 100F;
box1.Paragraphs.Add(text);
box1.BackgroundColor = new Aspose.Pdf.Color("Gray");
box1.BoxHeight = text.GetTextHeight(pdf1, text.TextWidth);
box1.BoxWidth = text.TextWidth;

FloatingBox box2 = new FloatingBox(108, 80);
box2.BoxHeight = text.GetTextHeight(pdf1, text.TextWidth);
box2.BoxWidth = text.TextWidth;
sec1.Paragraphs.Add(box2);
box2.BoxHorizontalPositioning = BoxHorizontalPositioningType.Margin;
box2.BoxHorizontalAlignment = BoxHorizontalAlignmentType.Right;
box2.BoxVerticalPositioning = BoxVerticalPositioningType.Page;
box2.BoxVerticalAlignment = BoxVerticalAlignmentType.Top;
box2.BackgroundColor = new Aspose.Pdf.Color("Red");

MessageBox.Show("" + text.GetTextHeight(pdf1, text.TextWidth).ToString());
pdf1.Save("d:/pdftest/TextHeighttest.pdf");

The resultant PDF generated with this code is also in attachment, please take a look.

That worked perfectly. Thank you.