HorizontalAlignment.Center Not Working

The application I am working needs to have functionality to place text that is wrapped to a given width and placed at different coordinates on a page.

Some of the text needs to centered horizontally.

I am able to place the text correctly and get the text to wrap to multiple lines.

I am not sure how to obtain a pdf where all of the wrapped lines are centered.

The following code will create a pdf using a long string that is wrapped to two lines (segments). The first segment appears to be centered. The second segment is positioned to start on the left (left alignment).

I have a couple of quesitons regarding the following code:

I am using the TextParagraph class. I set both the Horizontal Alignment and Vertical Alignment of the object. Does this setting override all of Text Fragments that are added to the Text Paragraph?

I created a TextFragment. I also set the Horizontal and Vertical Alignment of the Text Fragment. Does this setting override the setting of the TextParagraph that it is added to?
Is the Vertical Alignment value of the TextFragment ignored when it is added to a TextParagraph?

Is there a way to parse thru the segments of the TextParagraph at any point within this code prior to writing the pdf?

I have added an attachment that results from this code. Note the difference in Horizontal Alignment between the two lines.

    public static void CheckHorizontalAlignment()
    {

        Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
        Aspose.Pdf.Page p = doc.Pages.Add();
        p.PageInfo.Height = 11.0f * 72.0f;
        p.PageInfo.Width = 8.5f * 72.0f;
        p.PageInfo.Margin.Bottom = 0.0f;
        p.PageInfo.Margin.Top = 0.0f;
        p.PageInfo.Margin.Left = 0.0f;
        p.PageInfo.Margin.Right = 0.0f;
        Aspose.Pdf.Rectangle rect = new Rectangle(114.235046386719, 772.11953830719, 509.260620117188,
            787.40048122406);
        var txtBldr = new TextBuilder(p);
        var txtPara = new TextParagraph
        {
            FirstLineIndent = 0.0f,
            HorizontalAlignment = HorizontalAlignment.Center,
            VerticalAlignment = VerticalAlignment.Center,
            SubsequentLinesIndent = 0.0f,
            FormattingOptions = { WrapMode = TextFormattingOptions.WordWrapMode.ByWords },
            Rectangle = rect,
            Rotation = 0.0f
        };

        var tf = new TextFragment("REVISION AND APPROVAL OF THIS STANDARD NOTE IS CONTROLLED BY A DATA MANAGEMENT SYSTEM.  COPIES OF THIS RECORD ARE NOT CONTROLLED.   INFORMATION HEREON MAY NOT REFLECT THE LATEST APPROVED REVISION / VERSION OF THIS STANDARD NOTE.   ") { ZIndex = 1000 };
        tf.TextState.Font = FontRepository.FindFont("Arial");
        tf.TextState.FontSize = 6.34047174f;
        tf.TextState.ForegroundColor = Color.Black;
        tf.TextState.FontStyle= FontStyles.Regular;
        tf.TextState.HorizontalAlignment = HorizontalAlignment.Center;
        tf.VerticalAlignment = VerticalAlignment.Center;
        tf.TextState.Rotation = 0.0f;
        tf.TextState.HorizontalScaling = 90.5f;
        tf.TextState.LineSpacing = 1.30f;
        txtPara.BeginEdit();
        txtPara.AppendLine(tf);
        txtPara.EndEdit();
        txtBldr.AppendParagraph(txtPara);
        doc.Save("C:\\temp\\HorzontalAlignment.pdf");
    }

HorzontalAlignment.pdf (47.2 KB)

@csludtke

Thank you for contacting support.

We have logged an investigation ticket with ID PDFNET-46734 in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

Hello, @Farhan.Raza
Any updates on this??
I’ve been trying to achieve Horizontal Alignment with Aspose Pdf for java version 19.4 and had no luck…

@aiturricha

I regret to share that at present the issue is blocked by an enhancement feature. We are working on it and will share the good news with you as soon as the issue will be fixed.

Do you have an estimated time for the fix of this issue please?

@aiturricha

The blocker issue will hopefully be fixed in 21.6 release in June so you can expect the fix in couple of months.

Hello @mudassir.fayyaz,

Is the release out already? with the fix for this bug?

@aiturricha

I am afraid it is still unresolved. We will inform you as soon as it will be fixed.