Paragraph
Contents
[
Hide
]
Get Paragraph and Portion Coordinates in TextFrame
Using Aspose.Slides for Java, developers can now get the rectangular coordinates for Paragraph inside paragraphs collection of TextFrame. It also allows you to get the coordinates of portion inside portion collection of a paragraph. In this topic, we are going to demonstrate with the help of an example that how to get the rectangular coordinates for paragraph along with position of portion inside a paragraph.
AutoShape shape = (AutoShape)pres.getSlides().get_Item(0).getShapes().get_Item(0);
TextFrame textFrame = (TextFrame)shape.getTextFrame();
for (IParagraph paragraph : textFrame.getParagraphs()){
for (IPortion portion : paragraph.getPortions()){
Point2D.Float point = portion.getCoordinates();
}
}
Get Rectangular Coordinates of Paragraph
Using getRect() method developers can get paragraph bounds rectangle.
Presentation pres = new Presentation("HelloWorld.pptx");
try {
IAutoShape shape = (IAutoShape) pres.getSlides().get_Item(0).getShapes().get_Item(0);
ITextFrame textFrame = shape.getTextFrame();
Rectangle2D.Float rect = textFrame.getParagraphs().get_Item(0).getRect();
System.out.println("X: " + rect.x + " Y: " + rect.y + " Width: " + rect.width + " Height: " + rect.height);
} finally {
if (pres != null) pres.dispose();
}
Get size of paragraph and portion inside table cell text frame
To get the Portion or Paragraph size and coordinates in a table cell text frame, you can use the IPortion.getRect and IParagraph.getRect methods.
This sample code demonstrates the described operation:
Presentation pres = new Presentation("source.pptx");
try {
Table tbl = (Table)pres.getSlides().get_Item(0).getShapes().get_Item(0);
ICell cell = tbl.getRows().get_Item(1).get_Item(1);
double x = tbl.getX() + tbl.getRows().get_Item(1).get_Item(1).getOffsetX();
double y = tbl.getY() + tbl.getRows().get_Item(1).get_Item(1).getOffsetY();
for (IParagraph para : cell.getTextFrame().getParagraphs())
{
if (para.getText().equals(""))
continue;
Rectangle2D.Float rect = para.getRect();
IAutoShape shape =
pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle,
(float)rect.getX() + (float)x, (float)rect.getY() + (float)y, (float)rect.getWidth(), (float)rect.getHeight());
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.YELLOW);
shape.getLineFormat().getFillFormat().setFillType(FillType.Solid);
for (IPortion portion : para.getPortions())
{
if (portion.getText().contains("0"))
{
rect = portion.getRect();
shape =
pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle,
(float)rect.getX() + (float)x, (float)rect.getY() + (float)y, (float)rect.getWidth(), (float)rect.getHeight());
shape.getFillFormat().setFillType(FillType.NoFill);
}
}
}
} finally {
if (pres != null) pres.dispose();
}