Master slides

Hi, I have problem iterate throw master slides, first metod getMasters() return just first master slide not all of them, second how I can iterate throw shapes on master slide and get text but not text that generate office automatic, I need just text that is put on presentation by her creator. This is test:

public void test() {
PresentationEx presentation = new PresentationEx(
“/home/emisia/Desktop/master-slide-test.pptx”);
MasterSlideEx slide;
ShapesEx shps;

for (int index = 0; index < presentation.getMasters().getCount(); index++) {
// Accessing Slides
slide = presentation.getMasters().get_Item(index);
// Accessing all shapes in slide
shps = slide.getShapes();
ShapeEx shape;
// Traversing through all shapes
for (int shpCount = 0; shpCount < shps.getCount(); shpCount++) {
shape = shps.get_Item(shpCount);
if (shape.getPlaceholder() != null) {
if (!(shape instanceof PictureFrameEx)) {
// Getting AutoShape from group shapes set
AutoShapeEx aShape = (AutoShapeEx) shape;
if (aShape.getTextFrame() != null) {
// Accessing the text frame of shape
TextFrameEx tfText = aShape.getTextFrame();
System.out.println(tfText.getText());
}// End Text Frame IF
}// End AutoShape Check
} else if (shape instanceof AutoShapeEx) {
// Getting AutoShape from group shapes set

AutoShapeEx aShp = (AutoShapeEx) shape;
if (aShp.getTextFrame() != null) {
// Accessing the text frame of shape
TextFrameEx tfText = aShp.getTextFrame();
System.out.println(tfText.getText());
}// End Text Frame IF

}// End AutoShape Check

// If shape is a group shape
else if (shape instanceof GroupShapeEx) {
// Type casting shape to group shape
GroupShapeEx gShape = (GroupShapeEx) shape;
// Traversing through all shapes in group shape
for (int iCount = 0; iCount < gShape.getShapes().getCount(); iCount++) {
if (gShape.getShapes().get_Item(iCount) instanceof AutoShapeEx) {
// Getting AutoShape from group shapes set
AutoShapeEx aShp = (AutoShapeEx) gShape.getShapes()
.get_Item(iCount);
if (aShp.getTextFrame() != null) {
TextFrameEx tfText = aShp.getTextFrame();
System.out.println(tfText.getText());
}// End Text Frame IF
}
}
}
// If shape is instance of Table
else if (shape instanceof TableEx) {
TableEx tTable = (TableEx) shape;
for (int iCol = 0; iCol < tTable.getColumns().size()-1; iCol++) {
for (int iRow = 0; iRow < tTable.getRows().size()-1; iRow++) {
TextFrameEx tfText = tTable.get_Item(iCol, iRow)
.getTextFrame();
if (tfText != null)
System.out.println(tfText.getText());
}// End Row Loop
}// End Col Loop
}// End Group Shape IF

}// End Shape Loop

}// End Slide Traversal
}

Thanks

Hi,


I have observed the requirement shared by you. I feel you are probably looking to traverse through all layout slides in Master Slide. Actually, Master Slide is 1 in your presentation and that has Layout Slides inside it. In order to access the text of all slides, you need to access at Layout slide level. Secondly, in order to avoid the office automatic text, you can search for key string like “Click to” in text frame and discard that as an automatic text. There is no other way available to identify that if the text in text frame is office automatic or entered by user. Please try using the following sample code on your end to serve the purpose. You can modify the check token as per your own understanding. Please share, if I may help you further in this regard.

public static void testMasterShapes()
{
try{
String path=“D:\Aspose Data\”;
path=“C:\Presentations\”;
PresentationEx presentation = new PresentationEx(path+“master-slide-test.pptx”);
LayoutSlideEx slide;
// MasterSlideEx slide;
ShapesEx shps;

int cc= presentation.getMasters().getCount();
for (int index = 0; index < presentation.getLayoutSlides().getCount(); index++) {
// for (int index = 0; index < presentation.getMasters().getCount(); index++) {
// Accessing Slides
slide = presentation.getLayoutSlides().get_Item(index);
//slide = presentation.getMasters().get_Item(index);
// Accessing all shapes in slide
shps = slide.getShapes();
ShapeEx shape;
// Traversing through all shapes
for (int shpCount = 0; shpCount < shps.getCount(); shpCount++) {
shape = shps.get_Item(shpCount);
if (shape.getPlaceholder() != null) {
// Getting AutoShape from group shapes set
AutoShapeEx aShape = (AutoShapeEx) shape;
if (aShape.getTextFrame() != null) {
// Accessing the text frame of shape
TextFrameEx tfText = aShape.getTextFrame();
if(!tfText.getText().contains(“Click to”))
System.out.println(tfText.getText());
}// End Text Frame IF
}// End AutoShape Check
else if (shape instanceof AutoShapeEx) {
// Getting AutoShape from group shapes set
AutoShapeEx aShp = (AutoShapeEx) shape;
if (aShp.getTextFrame() != null) {
// Accessing the text frame of shape
TextFrameEx tfText = aShp.getTextFrame();
if(!tfText.getText().contains(“Click to”))
System.out.println(tfText.getText());
}// End Text Frame IF

}// End AutoShape Check

// If shape is a group shape
else if (shape instanceof GroupShapeEx) {
// Type casting shape to group shape
GroupShapeEx gShape = (GroupShapeEx) shape;
// Traversing through all shapes in group shape
for (int iCount = 0; iCount < gShape.getShapes().getCount(); iCount++) {
if (gShape.getShapes().get_Item(iCount) instanceof AutoShapeEx) {
// Getting AutoShape from group shapes set
AutoShapeEx aShp = (AutoShapeEx) gShape.getShapes()
.get_Item(iCount);
if (aShp.getTextFrame() != null) {
TextFrameEx tfText = aShp.getTextFrame();
if(!tfText.getText().contains(“Click to”))
System.out.println(tfText.getText());
}// End Text Frame IF
}
}
}
// If shape is instance of Table
else if (shape instanceof TableEx) {
TableEx tTable = (TableEx) shape;
int cntCol=tTable.getColumns().size();
int cntRow=tTable.getRows().size();
for (int iCol = 0; iCol < tTable.getColumns().size(); iCol++) {
for (int iRow = 0; iRow < tTable.getRows().size(); iRow++) {
TextFrameEx tfText = tTable.get_Item(iCol, iRow)
.getTextFrame();
if (tfText != null)
if(!tfText.getText().contains(“Click to”))
System.out.println(tfText.getText());
}// End Row Loop
}// End Col Loop
}// End Group Shape IF

}// End Shape Loop

}// End Slide Traversal
}
catch(Exception e)
{
e.printStackTrace();
}
}

Many Thanks,