We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to determine number of lines when word wrapping textfragment

We are trying to upgrade from Aspose.Pdf to the latest version due to restrictions/bugs in the older version that affect functionality we now need to implement. We are currently using a trial license for the new version while we convert our code to make sure it will work and have completed most of our development work but have run into a couple of issues. I will post separate threads for each so that they can be responded to individually.

This post is related to determining how many lines of text were used when text is printed in a container with a fixed width. In our old code we were able to call a GetTextHeight method and calculate based on the text size, however I do not seem to be able to find similar functionality in the new format.

Our new code to get it to word wrap is:

        Aspose.Pdf.Text.TextFragment pdfText = new Aspose.Pdf.Text.TextFragment(fPrintedMessage);
        pdfText.IsInLineParagraph = true;
        double singleLineHeight = pdfText.Rectangle.Height;
        double xIndent = GetColumnPosition(fColumn) - adjustLeft;

        float printHeight = Math.Ceiling(pdfText.Rectangle.Width / printWidth).IntNull(); //Aspose PDF newer version, couldn't figure out how to get the exact height of the box, so calculate the max height based on our wrap length and the text height as a single line
        FloatingBox fBox = new FloatingBox();
        fBox.IsInLineParagraph = true;
        fBox.Width = printWidth;
        fBox.Height = printHeight * singleLineHeight;

        fBox.Top = GetRowPosition(fRow);
        fBox.Left = xIndent;


And this works, the only issue is the pdfText rectangle box doesn’t update to the new height, and the FloatingBox height must be specified so we’re really just taking a best guess at it. Is there any way to know how much height was actually used by the textfragment (or, even better, how many lines were wrapped/used in total)?

Also, can you please provide some insight as to how to adjust the spacing between the lines. We found pdfText.TextState.LineSpacing but changing that is giving us some crazy behavior and the documentation on it is almost non-existant so we don’t really know what values to put into it.

Thank you.


Thank you for posting issues separately.

We have logged an investigation ticket with ID PDFNET-46032 in our issue management system for detailed investigations into your requirements. We will let you know as soon as some significant updates will be available in this regard.

Any updates on this?


Thank you for getting back to us.

We are afraid this ticket is currently pending for investigations and may take few more months. However, we have recorded your concerns and will notify you as soon as it is resolved. We appreciate your patience in this regard.