We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unable to get the RectangleF of a paragraph located in a cell of a table in slides

Hello,

I am trying to get the RectangleF of a Paragraph in a cell of a table in slides, but when I get the paragraph located in the cell and I want to get the RectangleF using this code:
Rect = new RectangleF(paragraph.GetRect().X, paragraph.GetRect().Y, paragraph.GetRect().Width, paragraph.GetRect().Height);
I get the below exception:
Message = “Unable to cast object of type ‘Aspose.Slides.Cell’ to type ‘Aspose.Slides.GeometryShape’.”
I am using IParagraph interface to obtain the paragraph. Pls tell me what’s going on

@Trickstar

Can you please share source file along with complete code snippet so that we may further investigate to help you out.

Thanks for your swift reply,
Unfortunately, I can’t upload a file of pptx so I uploaded an Image instead
here is a sample code:
var presentation = new Presentation(file);
List paragraphsRect = new List();
foreach (var slide in presentation.Slides)
{
foreach (var shape in slide.Shapes)
{
if (shape is ITable)
{
foreach (IColumn column in ((ITable)shape).Columns)
foreach (ICell cell in column)
foreach (IParagraph paragraph in cell.TextFrame.Paragraphs)
paragraphsRect.Add(paragraph.GetRect());
}
}
}
result_0.png (11.8 KB)

@Trickstar,

Can you please share source presentation file, This will help us to resolve issue as soon as possible. You can share source file via Dropbox as well.

@Adnan.Ahmad Okay, Here is the link https://www.dropbox.com/s/5kt1k0ud25621ts/source.pptx?dl=0

@Trickstar,

I have shared sample code with you. This will help you to achieve your requirements. Please share feedback with us if there is still an issue.

using (Presentation presentation = new Presentation(path+“Test.pptx”))
{
foreach (IShape shape in presentation.Slides[0].Shapes)
{
Table table = shape as Table;
if (table != null)
{
Cell tableCell = table.Rows[0][0] as Cell;
Console.WriteLine("Cell: "+ tableCell.TextFrame.Text);
RectangleF frameRect = new RectangleF(
(float)(table.X + tableCell.OffsetX),
(float)(table.Y + tableCell.OffsetY),
(float)(tableCell.Width),
(float)(tableCell.Height));
Console.WriteLine("Cell frame: " + frameRect);

                }
            }
      }

@Adnan.Ahmad Thanks once again for your swift reply,
This is how to get the coordinates of the cell, I want to know if it is possible to get the paragraph and also the portion in the paragraph coordinates in that particular cell.

@Trickstar,

I like to inform that we dont have function for instant getting of paragraphs/potions coordinates. You have to calculate it by yourself. If there is still an issue than please share requirements we will investigate further on our end to help you out.

@Adnan.Ahmad Okay, thank you for your reply, One last question, is it possible to get the width of a portion in a paragraph?

@Trickstar,

I regret to share that at present the support for getting the size of Portion or Paragraph inside TextFrame is not available in API. An issue with ID SLIDESNET-40977 has been created in our issue tracking system to provide the requested support. We will share the good news with you as soon as the issue will be fixed.

@mudassir.fayyaz,

Do you have any updates, because in my project are required to get Top,Left,Bottom, Right (or X,Y, Width, Height) positions for paragraph in table cell too.

@aaksenov,

I have verified from our issue tracking system and regret to share that at present the requested support is not available in API. I have requested for further updates in this regard and will share them with you as soon as the feedback will be shared.

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

We got the latest version with table cell paragraph which has Y and Bottom properties with other properties. Thanks for that!

So just want to check how we can decide if any paragraph is out of slide so that we can move it to next slide. (Paragraphs are present in table rows-> cell->textframe)

How to check if paragraph is out of slide ? and we found that table’s Y position + height is different than table’s last paragraph bottom coordinates. Ideally both should be same right?

@sisodeB,

There is no direct method to check if any text frame height is out of slide bounds and one need to add new slide. You have to devise your own logic in this regard to keep checking the table height while adding text to cell. If at any stage the table Y + height is greater than slide height, you will get to know that last addition of text reached the slide bounds and you will add new slide and add same text back again. It’s dependent purely on your application and your own logic.

Yes. We have that logic to check if slide overflow using Table.Y + height but in case of paragraph in table cell(Textframe), bottom position of paragraph is less than Table.Y + height even though it is overflown in same slide(paragraph in context is matching with table bottom but there is major difference paragraph bottom and Table.Y + height. Same is the case with Size.Height.
Any thought on this?

We have below data where there is blank middle column and in this case bottom position of left and right columns last paragraph are not calculating correctly. If we remove blank column, bottom calculation is fine. Can you please create this ticket?

This only happens with certain set of data as shown in image.

image.png (10.0 KB)

@sisodeB,

I am sorry, I didn’t get much from your following explanation. We need to understand that what matters in table row is height of cell. The text frame is encapsulated in table cell and paragraph collection is part of text frame. p@hromkes,

I have observed the issue shared by you and like to share that Aspose.Email for .NET has no issue while using it in NET Core 3.1 environment. Can you please provide the sample project for investigation on our end. So, we can’t measure based on paragraph height with table height.

I would request you to please share the sample application with achieved results, desired results and snapshot explaining the issue.