Getting X and Y Position for Paragraphs (C# .NET)

Hi Alexey,

I want to get position (x and y) for each paragraph in TextFrame. How can I do this? Can you add any property to Aspose which will help me to find this position (for example height of paragraph)?

Dear CAV,

It looks like I answered this your question some time ago.
Now you have frame coordinates, text, font, size, margins and etc.
It’s enough to calculate paragraph position.

@CAV,

We have added the support for getting the size as well as X,Y position of paragraph and portions inside text frame of any shape on slide. In the following example, we have demonstrated the use of API feature where you can extract the paragraph as well as portion X,Y position 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)