Problem with text alignment in paragraph

Hi.



I do not seem to be able to make text added to a paragraph align properly.



If I use the Alignment property the text is not shown in Powerpoint, however it seems to work in OpenOffice.


Code below -


Aspose.Slides.Rectangle bitName = slide.Shapes.AddRectangle(1000, 1000, 250, 120);


TextFrame bitNameTF = bitName.AddTextFrame("");

bitNameTF.MarginTop = 0;

bitNameTF.MarginLeft = 2;

bitNameTF.MarginBottom = 7.5;

bitNameTF.LineFormat.ShowLines = true;



Portion bitPort2 = new Portion();

bitPort2.Text = "some text";


bitPort2.FontColor = Color.Black;

bitPort2.FontHeight = 13;

Paragraph bitPara2 = new Paragraph();

bitPara2.Alignment = TextAlignment.Right;

bitPara2.Portions.Add(bitPort2);



bitNameTF.Paragraphs.Add(bitPara2);



Any ideas?



Thanks.


John
This message was posted using Page2Forum from
Managing Paragraph Alignment - Aspose.Slides for .NET

Hi John,

I've executed the code snippet that you've shared with Aspose.Slides for .NET 4.1.0 and I'm able to notice the same problem. I've also tried setting the Alignment values to Center and Justify but the output in resultant PPT is still left aligned. It seems to be an issue with Aspose.Slides and I think the team would in better position to share their comments regarding its resolution.

Hello Aspose.Slides team,

I've noticed that, when using the properties of Portion class such as FontUnderline, FontBold and FontItalic, they are not working. The only property that seems to be working correctly is FontColor. Can you please check this matter as well.

Hi Jhon,

For a concept on managing multiple paragraphs and portions in a TextFrame visit this topic. For your current requirement, use the following code instead:

Aspose.Slides.Rectangle bitName = slide.Shapes.AddRectangle(1000, 1000, 1000, 500);

TextFrame bitNameTF = bitName.AddTextFrame("Some Text");

bitNameTF.MarginTop = 0;

bitNameTF.MarginLeft = 2;

bitNameTF.MarginBottom = 7.5;

bitNameTF.LineFormat.ShowLines = true;

Aspose.Slides.Paragraph bitPara2 = bitNameTF.Paragraphs[0];

bitPara2.Alignment = TextAlignment.Right;

Portion bitPort2 = bitNameTF.Paragraphs[0].Portions[0];

bitPort2.FontColor = Color.Black;

bitPort2.FontHeight = 13;

Hi Mudassir,

Please use the code i have just added in my previous post and check it out with FontBold / Italic and Underline properties.

Hi Sabir,

Thanks for the correction.

After going through your code snippet, I am able to figure out the reason of issue. In your code you've explicitly specified bitPara2 as paragraph at index 0 for bitNameTF (TextFrame), whereas in my code, I created an object with empty constructor and added it paragraphs collection of bitNameTF with bitNameTF.Paragraphs.Add(bitPara2) statement. Now that I have changed the code line, I can see the text a Right Aligned.

For second issue regarding FontItalic, FontBold and FontUnderline, I called empty constructor of Portion class to create bitPort2 object and later on added it to portions collection of bitPara2 (Paragraph object) using bitPara2.Portions.Add(bitPort2); but in your code I've noticed that you've created an object while specifying it as the portion at index 0. So, I have also changed my line from Portion bitPort2 = new Portion(); to Portion bitPort2 = bitPara2.Portions[0]; and properties related to Font formatting are working correctly.

Thanks for your support.

Hi Mudassir,

The concept behind it is that, whenever a TextFrame is created, it already has a Paragraph object at index 0, and this paragraph has further a Portion object at index 0. For managing multiple paragraphs with multiple portions associated with a TextFrame, you can get an idea from this topic.

Thanks for all you help on this!!!



Cheers.



John