I’m using Aspose.slides in Java.
My usecase comprises of iterating over each slide and extracting the y-coordinate value of each paragraph, relative to the height of the slide.
For example, if the slide is of 600x500 dimension, then the first paragraph would roughly start at a y-coordinate of ~50ish & last would start at somehere 450ish.
I tried various methods like:
double y = paragraph.getRect().getCenterY();
float y = paragraph.getRect().y;
float y = portion.getRect().height;
float y = portion.getCoordinates().y;
double y = portion.getCoordinates().getY();
But all of them are pointing to the y-coordinate relative to the 2D rectangle around the paragraph/portion and not the slide as whole.
Sample code:
Presentation pres = new Presentation(pptxFilePath);
ISlideSize slideSize = pres.getSlideSize();
// get the slide height for referencing
float slideHeight = (float) slideSize.getSize().getHeight();
// Extracting all text frames from the presentation
ITextFrame[] textFramesPPTX = SlideUtil.getAllTextFrames(pres, false);
// Looping through the extracted text frames
for (ITextFrame textFrame : textFramesPPTX) {
// Looping through each paragraphs
for (IParagraph para : textFrame.getParagraphs()) {
// logic to get paragraph's y axis relative to "slideHeight"
}
}
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESJAVA-39512
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@cacglo,
The paragraph coordinates are calculated relative to the shape it is in. The SlideUtil.getAllTextFrames does not support getting shape coordinates, because it returns ITextFrame items. We will consider adding another method to this class to get coordinates of shapes.
You can get the y-coordinate relative to the entire slide using the current Slides API. Please use the following code snippet:
Presentation pres = new Presentation(presPptx);
ArrayList<ITextFrame> textFrames = new ArrayList<>();
for (ISlide slide : pres.getSlides())
getAllTextFrames (slide.getShapes(), textFrames);
static void getAllTextFrames(IShapeCollection shapes, ArrayList<ITextFrame> textFrames)
{
for (int i = 0; i < shapes.size(); i++)
{
IShape currentShape = shapes.get_Item(i);
if (currentShape instanceof IGroupShape)
{
getAllTextFrames(((IGroupShape) currentShape).getShapes(), textFrames);
}
else
{
if (currentShape instanceof IAutoShape)
{
IAutoShape ash = (IAutoShape) currentShape;
ITextFrame textFrame = ash.getTextFrame();
if (textFrame != null) {
textFrames.add(textFrame);
calculateYAndPrint(textFrame, ash.getY());
}
continue;
}
if (currentShape instanceof Table)
{
ITable table = (ITable) currentShape;
for (int row = 0; row < table.getRows().size(); row++)
{
for (int col = 0; col < table.getColumns().size(); col++)
{
ICell cell = table.getRows().get_Item(row).get_Item(col);
if (cell.getTextFrame() != null) {
textFrames.add(cell.getTextFrame());
calculateYAndPrint(cell.getTextFrame(), table.getY());
}
}
}
continue;
}
if (currentShape instanceof IChart)
{
IChart chart = (IChart) currentShape;
if (chart.getUserShapes() != null)
{
getAllTextFrames(chart.getUserShapes().getShapes(), textFrames);
continue;
}
}
if (currentShape instanceof ISmartArt)
{
ISmartArt smartArt = (ISmartArt) currentShape;
ISmartArtNodeCollection nodes = smartArt.getAllNodes();
for (ISmartArtNode node : nodes)
{
textFrames.add(node.getTextFrame());
calculateYAndPrint(node.getTextFrame(), smartArt.getY());
}
}
}
}
}
static void calculateYAndPrint(ITextFrame textFrame, float shapeY)
{
for (IParagraph para : textFrame.getParagraphs()) {
double y = para.getRect().getY();
System.out.println(y + shapeY);
}
}