I need to extract text from master slides, but when I get slide.getMasters() and try to extact text like in my test:
public void test() {
PresentationEx presentation = new PresentationEx(
“PTBR Avnet Wallcharts_FP_1.6.2011_02.pptx”);
// MasterSlideEx slide;
// ShapesEx shps;
LayoutSlideEx slide;
// MasterSlideEx slide;
ShapesEx shps;
// iterate(presentation.getMasters().get_Item(0).getShapes());
for (int masterIndex = 0; masterIndex < presentation.getMasters()
.getCount(); masterIndex++) {
int m=presentation.getMasters()
.getCount();
MasterSlideEx main = presentation.getMasters()
.get_Item(masterIndex);
iterate(main.getShapes());
}
LayoutSlidesEx masters = presentation.getLayoutSlides();
for (int masterIndex = 0; masterIndex < presentation.getLayoutSlides()
.getCount(); masterIndex++) {
LayoutSlideEx master = masters.get_Item(masterIndex);
iterate(master.getShapes());
}
}
private void iterate(ShapesEx shapes) {
ParagraphsEx paragraphs = null;
ShapeEx shape;
// Traversing through all shapes
for (int shpCount = 0; shpCount < shapes.getCount(); shpCount++) {
int s=shapes.getCount();
shape = shapes.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 (!aShape.isTextHolder())
paragraphs = tfText.getParagraphs();
if (paragraphs != null)
for (int i = 0; i < paragraphs.getCount(); i++) {
System.out.println(paragraphs.get_Item(i)
.getText());
}
// iterateParagraphs(paragraphs, paragraphList);
}// 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 (!aShp.isTextHolder())
paragraphs = tfText.getParagraphs();
if (paragraphs != null)
for (int i = 0; i < paragraphs.getCount(); i++) {
System.out.println(paragraphs.get_Item(i)
.getText());
}
// iterateParagraphs(paragraphs, paragraphList);
}// 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 (!aShp.isTextHolder())
paragraphs = tfText.getParagraphs();
if (paragraphs != null)
for (int i = 0; i < paragraphs.getCount(); i++) {
System.out.println(paragraphs.get_Item(
i).getText());
}
// iterateParagraphs(paragraphs, paragraphList);
}// 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)
if (!shape.isTextHolder())
paragraphs = tfText.getParagraphs();
if (paragraphs != null)
for (int i = 0; i < paragraphs.getCount(); i++) {
System.out.println(paragraphs.get_Item(i)
.getText());
}
// iterateParagraphs(paragraphs, paragraphList);
}// End Row Loop
}// End Col Loop
}// End Group Shape IF
}// End Shape Loop
}// End Slide Traversal
}
it returns me text from masters few times more than it should. there is text on 3 masters slide but returns me 5 times. How can I fix this, can You help me?