When creating an `Aspose.Pdf.Text.TextFragment` object, the property for TextState.HorizontalAlignment is not respected

For Aspose.Pdf Version=“24.3.0”

When creating an Aspose.Pdf.Text.TextFragment object, the property for TextState.HorizontalAlignment is not respected when that object is assigned to a Aspose.Pdf.Drawing.Rectangle object through the .Text property, nor when the Aspose.Pdf.Drawing.Rectangle’s Text.HorizontalAlignment property is set.
Text items in this case will always have center alignment.

TextFragment item = new("The quick brown fox jumps over the lazy dog.");
item.TextState.HorizontalAlignment = HorizontalAlignment.Left;
item.TextState.VerticalAlignment = HorizontalAlignment.Left;

Rectangle container = new(0, 0, 100, 100);
container.Text = item;
container.Text.HorizontalAlignment = HorizontalAlignment.Left;

When creating an Aspose.Pdf.Drawing.Rectangle object, setting the RoundedCornerRadius property will only work if a GraphInfo.FillColor property is not set, preventing the shape from having a fill color. When both of these properties are set, no shape will be rendered to the pdf document.

Rectangle item = new(0, 0, 100, 100);
item.GraphInfo.FillColor = Color.Red;
item.RoundedCornerRadius = 1;

When the Paragraphs.Add() method is invoked on a Aspose.Pdf.Page, and that content would overflow the page contents, this method seems to automatically create a new page and append the content there. The mechanism that would validate whether there is an appropriate amount of space for an element seems to be calculating incorrectly with shapes, such as with a Aspose.Pdf.Drawing.Rectangle object. In the following example, the last three Rectangle items are each pushed individually to three new pages to fit them alone.

private void CreateItem(Page page, Position position)
{
    Color borderColor = Color.FromArgb(224, 224, 224);
    Graph canvas = new Graph(235.0 / d, 277.0 / d)
    {
        IsInNewPage = false,
        Left = position.XIndent,
        Top = position.YIndent
    };

    Rectangle border = new(0, 0, 235 / d, 277 / d);
    border.GraphInfo.Color = borderColor;
    border.GraphInfo.LineWidth = 1;
    border.RoundedCornerRadius = 1;
    canvas.Shapes.Add(border);

    page.Paragraphs.Add(canvas);
}

public Document CreateTestDocument()
{
    int margin = 35;
    int xOffset = 135;
    int yOffset = 150;
    Document document = new();
    Page page = document.Pages.Add();
    MarginInfo pageMargin = new()
    {
        Left = margin,
        Right = margin,
        Top = margin,
        Bottom = margin
    };

    page.PageInfo.Margin = pageMargin;

    for (int row = 0; row < 5; row++)
    {
        for (int col = 0; col < 4; col++)
        {
            CreateItem(page, new Position(xOffset * col, yOffset * row));
        }
    }

    return document;
}

ShapeExample.pdf (3.0 KB)

@jsarasqueta

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-56888

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.