We are trying to upgrade from Aspose.Pdf 8.3.1.0 to the latest version 19.1.0.0 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;
fBox.Paragraphs.Add(pdfText);
fPdfPage.Paragraphs.Add(fBox);
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.