How to get Paragraph position on slide (C# .NET)

Can you point me toward your instruction on determining the y position of a paragraph in slides?

Hi Michael,

Thank you for your interest in Aspose.Slides.


I have observed your comments and like to share with you that there is not any property in Aspose.Slides, which could be used to determine position coordinates of a paragraph. However, a ticket with ID SLIDESNET-36886 has been logged into our issue management system, as a new feature request. I have linked the issue with this thread so that you may be notified automatically as soon as the issue will be resolved.

Best Regards,

The issues you have found earlier (filed as SLIDESNET-36886) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(4)

@aspose-29,

Now, Aspose.Slides API provides the provision to access the actual coordinates on slide for any text frame paragraph or its respective portions. In the following example, you can use verify the usage of the feature. We have also attached sample presentation for your convenience too.

	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)