Hi,
How can I get coordinates (x,y) of the text/paragraph/portion within frame or slide doesn’t matter.
Please, give answer to ppt and pptx.
Regards,
Hi,
Hi Leonid,
The new Aspose.Slides API provides you the support for accessing the coordinates position for any text available on slide. As you know the text on slide is actually enclosed in a text frame for any shape. The text frame has got collection of paragraphs and each paragraph contain collection of portions inside it. We have introduced support where you can now access the coordinates of any text available on slide not only on paragraph but portion level well as. In the following example, I hope you will be able to fulfill your requirements for accessing the coordinates for any text on slide.
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)