I would like to determine the height of a FloatingBox that is required for a multi-line TextFragment

I am creating a from scratch. I would like to position a long text string within a rectangular region on a page.

I would like to define the width of the rectangle, the font textState properties and the text that will be added to the FloatingBox. I would like the text to be divided into multiple lines if required (by word).

Is there a way to obtain the number of resulting lines used and the resulting minimum height of the FloatingBox to include all of the text?

@csludtke

Thank you for contacting support.

You may add any text in a rectangular region using Table object where you can specify the width but not necessarily the height because specifying suitable height may not be possible while generating document. Suggested table approach will calculate the height automatically whereas you may also disable the borders as per your requirements.

// Initiate PDF document
Document doc = new Document();
// Add page
Page page = doc.Pages.Add();
// Initializes a new instance of the Table
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.ColumnWidths = "150";
// Set the table border color as LightGray
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Set the border for table cells
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Add row to table
Aspose.Pdf.Row row = table.Rows.Add();
// Add table cells
TextFragment fragment = new TextFragment("Very long text Very long text Very long text Very long text Very long text");
Aspose.Pdf.Cell cell = new Aspose.Pdf.Cell();
cell.Paragraphs.Add(fragment);
row.Cells.Add(cell);
// Add table object to first page of input document
page.Paragraphs.Add(table);
doc.Save(outFile);

We hope this will be helpful. Please feel free to contact us if you need any further assistance.