There is some text inside a shape. (Create the page from the default ppt theme)
We can get the position and size of the red rectangle. but how about the green one( the exact text frame position without margin, padding etc.)
There is some text inside a shape. (Create the page from the default ppt theme)
Hi Jollibee,
I tried the sample code, but I didn’t get what I want.
Hi Jollibee,
Hi Jollibee,
You’re right. I can get the anchoring type from your code.
Hi Jollibee,
I have observed your requirements and like to share that Aspose.Slides exposes the API calls to not only access any paragraph’s but its respective portions position coordinates. Which includes access to X, Y position, width and height of any paragraph or portion belonging to any text frame. The following example demonstrates the usage of the API calls to fulfill the requirement.
public static void GetParagraphCoordinates()
{
// The path to the documents directory.
string dataDir = @"C:\Aspose Data\";
// Instantiate a Presentation object that represents a presentation file
using (Presentation presentation = new Presentation(dataDir + "TestText.pptx"))
{
IAutoShape shape = (IAutoShape)presentation.Slides[0].Shapes[0];
var textFrame = (ITextFrame)shape.TextFrame;
RectangleF rect = ((Paragraph)textFrame.Paragraphs[0]).GetRect();
Console.WriteLine("The following shows the paragraph's actual coordinates on slide");
Console.WriteLine(String.Format("Paragraph Text: {4} has coordinates (X: {0}, Y: {1}), Width: {2} and Height{3}", rect.X, rect.Y, rect.Width, rect.Height, ((Paragraph)textFrame.Paragraphs[0]).Text));
}
}
public static void GetPortionCoordinates()
{
string dataDir = @"C:\Aspose Data\";
using (Presentation presentation = new Presentation(dataDir + "TestText.pptx"))
{
IAutoShape shape = (IAutoShape)presentation.Slides[0].Shapes[0];
var textFrame = (ITextFrame)shape.TextFrame;
foreach (var paragraph in textFrame.Paragraphs)
{
Console.WriteLine("The following shows the coordinates for all the portions inside paragraph");
foreach (Portion portion in paragraph.Portions)
{
var rect = portion.GetRect();//.GetCoordinates();
//Console.Write(Environment.NewLine + "Corrdinates X =" + point.X + " Corrdinates Y =" + point.Y);
Console.WriteLine(String.Format("Portion Text: {4} has coordinates (X: {0}, Y: {1}), Width: {2} and Height{3}", rect.X, rect.Y, rect.Width, rect.Height, portion.Text));
}
}
}
}
TestText.zip (24.0 KB)