FloatingBox TextVerticalAlignment not working with FixedHeight

Hello,

I seem to be having some vertical alignment issues when trying to set a fixed height on a Text control while setting the TextVerticalAlignment on its parent FloatingBox control. The code below should help with this explanation:

protected void BuildText(string text, Aspose.Pdf.Generator.Section currentSection, Aspose.Pdf.Pdf pdf)
{
float boxWidth = 50;
float boxHeight = 100;

FloatingBox box = new FloatingBox(boxWidth, boxHeight);
Aspose.Pdf.Generator.Text t = new Aspose.Pdf.Generator.Text(text);

box.Left = 0;
box.Top = 0;

Aspose.Pdf.Generator.TextInfo ti = new Aspose.Pdf.Generator.TextInfo();
ti.FontName = “Lucida Console”;
ti.FontSize = 11;

ti.Alignment = AlignmentType.Center;
box.TextVerticalAlignment = VerticalAlignmentType.Center;

t.TextInfo = ti;
box.Paragraphs.Add(t);
currentSection.AddParagraph(box);
}

This code seems to work fine, however, if the ‘text’ parameter is large enough where it extends beyond the size of the FloatingBox (i.e. larger than 50 px tall), I want to cut off the text that is outside the box.

With that in mind, I was able to find a way to do this, using the following line of code:

t.FixedHeight = 50;

The problem, however, is that when the FixedHeight property is set, I have seen two separate issues (one in my actual program, and the other in my test program). The first problem, is that it causes the TextVerticalAlignment to stop working entirely, making it so that everything is aligned to the top. The second problem (from my test program) is that it seems to cause the text to lose its TextInfo, and the text ends up being the wrong size, etc.

Any chance you might be able to give me some hints on what I need to do to get around the problem?

I have attached a couple examples of my results, and my expected results, to help.

Thanks,
Eric

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

Thank you for considering Aspose.Pdf for .NET.

I think you are using an older version of Aspose.Pdf for .NET. We have merged Aspose.Pdf for .NET and Aspose.Pdf.Kit for .NET in to one product. Please try the latest version of Aspose.Pdf for .NET v6.4.2 and check if it works fine for you. Please do let us know if you still face any problem.

Thank You & Best Regards,

I have updated to the latest version of Aspose.Pdf for .NET (v6.4.2) and the problem still appears to be occurring.

After nearly 8 months of no reply to my previous response, I decided to upgrade to the newest version (7.1.0) and this problem is still not fixed. However, I do have some new information that may be useful in tracking down the issue. Here is the entirety of my code:

public Form1()
{
InitializeComponent();
Testing();
}
void Testing()
{
Aspose.Pdf.Generator.Pdf pdf = new Pdf(new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Write));
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
FloatingBox box = new FloatingBox(500, 500);
box.Border = new BorderInfo((int)BorderSide.All, 3f, new Aspose.Pdf.Generator.Color(“Green”));
box.Left = 0;
box.Top = 0;
section.Paragraphs.Add(box);
BuildText(“The quick brown fox\r\njumped over the very\r\nlazy dog.”, section, pdf);
System.IO.FileInfo finfo = new System.IO.FileInfo(fileName);
pdf.Close();
}
protected void BuildText(string text, Aspose.Pdf.Generator.Section currentSection, Aspose.Pdf.Generator.Pdf pdf)
{
float boxWidth = 100;
float boxHeight = 100;
FloatingBox box = new FloatingBox(boxWidth, boxHeight);
box.Border = new BorderInfo((int)BorderSide.All, 3f, new Aspose.Pdf.Generator.Color(“Green”));
Aspose.Pdf.Generator.Text t = new Aspose.Pdf.Generator.Text(text);
box.Left = 0;
box.Top = 0;
Aspose.Pdf.Generator.TextInfo ti = new Aspose.Pdf.Generator.TextInfo();
ti.FontName = “Lucida Console”;
ti.FontSize = 11;
ti.Alignment = AlignmentType.Center;
box.TextVerticalAlignment = VerticalAlignmentType.Center;
t.TextInfo = ti;
//t.FixedHeight = 100;
box.Paragraphs.Add(t);
currentSection.AddParagraph(box);
}

Toward the end of the code you will notice that I have a line commented out (t.FixedHeight = 100). If you uncomment this code, you should notice that the text that is displayed in the PDF becomes top aligned instead of center aligned. However, if you change this value to be something smaller than the size of the floating box (say 75) you will notice that the text does not go all the way to the top of the floating box, but is still not center aligned.

This leads me to believe that what is occurring is that the Text paragraph has an outer “box” that is getting center aligned, but that it also has an inner “box” that is aligning to the top whenever you set the FixedHeight.

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

Thank you for sharing the sample code and please accept our apologies for a delay in reply.

We are testing your issue and will get back to you soon.

Sorry for the inconvenience,