Hi,
auto textFrameFormat = shape->get_TextFrame()->get_TextFrameFormat();
auto anchor = textFrameFormat->get_AnchoringType();
get_Anchoring returns undefined for the attached presentation.
The set text vertical alignment is Bottom in the ppt.
Please look into this.
group.pptx.zip (26.6 KB)
using aspose 24.5 version
@pankajku
It seems that you are having trouble retrieving the anchoring type for the vertical alignment of text in your PowerPoint presentation using Aspose.Slides. The method get_AnchoringType()
returning undefined could be due to a few reasons.
To ensure you are accessing the correct properties, you might want to check the following:
-
Effective Text Frame Format: Instead of directly accessing the AnchoringType
from the TextFrameFormat
, you should retrieve the effective format. This can be done using the GetEffective()
method on the TextFrameFormat
object. This will give you the actual properties that are applied to the text frame, including the anchoring type.
Here is a code snippet that demonstrates how to do this:
// Assuming 'shape' is your SharedPtr<IAutoShape> object
auto textFrameFormat = shape->get_TextFrame()->get_TextFrameFormat();
auto effectiveTextFrameFormat = textFrameFormat->GetEffective();
auto anchor = effectiveTextFrameFormat->get_AnchoringType();
-
Check the Presentation File: Ensure that the presentation file you are working with actually has the text frame set to the desired vertical alignment. You can verify this by checking the properties of the text frame in the PowerPoint application.
-
Version Compatibility: Since you are using Aspose version 24.5, make sure that this version supports the features you are trying to use. If possible, consider updating to a newer version of Aspose.Slides, as there may have been bug fixes or enhancements related to text formatting and anchoring.
If you follow these steps and still encounter issues, please provide more details about the specific code you are using and any error messages you receive. This will help in diagnosing the problem further.
Feel free to reach out if you have any more questions or need further assistance!
Hi, Thanks you for sharing this. There is slight problem with this. For Bottom-Centered, Top-Centered and Middle-Centered in the verticalAlignment for ppt, I am getting the Anchor type as Bottom, top and middle. Is there a way to get Bottom-Centered, Top-Centered and Middle-Centered using any other aspose api?
Additionally, is there a way to get the numerical value of the vertical alignments?
TextAnchorType::Center
numerical value of this for example?
@pankajku,
In PowerPoint, there is vertical alignment of text box content and horizontal alignment of paragraphs.
You can get the vertical alignment of the text box content as shown below:
auto anchorType = autoShape->get_TextFrame()->get_TextFrameFormat()->GetEffective()->get_AnchoringType(); // Top, Center, Bottom, etc.
You can get the horizontal alignment of a paragraph like this:
auto alignmentType = paragraph->get_ParagraphFormat()->GetEffective()->get_Alignment(); // Left, Center, Right. etc.
The TextAnchorType
inherits the int8_t
type, so you can get a numerical value of the anchor type as shown below:
int8_t anchorValue = static_cast<int8_t>(anchorType);
More examples: Text Formatting|Aspose.Slides Documentation
Hi @andrey.potapov
auto anchorType = autoShape->get_TextFrame()->get_TextFrameFormat()->GetEffective()->get_AnchoringType();
this we are already using.
We get Top
, Center
and Bottom
.
However, in powerpoint we have Top-Center, Bottom-Center and Middle-Center. When we set this, the horizontal alignment remains left if not changed, but the text gets centered. However, Top-Center, Bottom-Center and Middle-Center still comes as Top, Center and Bottom from get_AnchoringType()
.
How do we get Top-Center, Bottom-Center and Middle-Center ?
2nd question →
int8_t anchorValue = static_cast<int8_t>(anchorType);
anchorType
comes as center but anchorValue = '\x01'
@pankajku,
Could you please show me on a screenshot where it is in PowerPoint? I was unable to find it.
Please try using the following:
int anchorValue = static_cast<int>(anchorType);
Screenshot 2025-05-19 at 4.33.13 PM.jpg (89.8 KB)
@andrey.potapov Pls go through attached screenshot.
int anchorValue = static_cast<int>(anchorType);
this works. But what is this anchor value representing? cm shift in the text box or some other property?
@pankajku,
Thank you for the clarification. I’ve reproduced the problem with extracting the vertical alignment value of the text box content.
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): SLIDESCPP-4028
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.
@pankajku,
Our developers have reviewed your requirements. To obtain the shape’s anchoring property as in PowerPoint, please use a combination of the get_AnchoringType()
and get_CenterText()
methods. For example:
auto frameFormat = autoShape->get_TextFrame()->get_TextFrameFormat()->GetEffective();
auto anchorType = frameFormat->get_AnchoringType();
bool centerText = frameFormat->get_CenterText();
Console::WriteLine(u"Anchor Type: {0}{1}",
ObjectExt::ToString(anchorType), centerText ? u" Centered" : u"");
Output:
Anchor Type: Bottom Centered