Master Slide pptx

Hi,


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?

Hi,

I have tried to observe the issue shared by you and unfortunately have not been able to identify the point where issue is incurring. Can you please share the details about the issue that on which layout slide you are getting text more than the times it should return while extraction. Please also share the expected result as well and I will carry out my investigation on the basis of that.

Many Thanks,

Hi,

it is not text from layout slides, it’s about text from masters slide, slide.getMasters(), in my presentation there is 8 masters slide, that returns mentioned metod, and on 3 there is text “Accelerating Your Success™” but my test return 5 times this text. Here is test again:

public void test() {
PresentationEx presentation = new PresentationEx(
“PTBR Avnet Wallcharts_FP_1.6.2011_02.pptx”);

LayoutSlideEx slide;
ShapesEx shps;
for (int masterIndex = 0; masterIndex < presentation.getMasters()
.getCount(); masterIndex++) {
MasterSlideEx main = presentation.getMasters()
.get_Item(masterIndex);

iterate(main.getShapes());

}
presentation.write(“master.pptx”);
}

public void iterate(ShapesEx shps) {

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 (!aShape.isTextHolder()) {
System.out.println(tfText.getText());
tfText.setText(“T” + 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 (!aShp.isTextHolder()) {
System.out.println(tfText.getText());
tfText.setText(“T” + 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 (!aShp.isTextHolder()) {
System.out.println(tfText.getText());
tfText.setText(“T” + 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() - 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()) {
System.out.println(tfText.getText());
tfText.setText(“T” + tfText.getText());
}
}// End Row Loop
}// End Col Loop
}// End Group Shape IF

}// End Shape Loop
}// End Slide Traversal
}


Thanks

Hi,

I have worked with the presentation file shared by you and like to share that there is no issue with Aspose.Slides while extracting the text from master slides. The issue actually lies in the presentation master slides 2 and 8. Actually, there are two shapes with text “Accelerating Your Success™”" that are super imposed. Visually, the look as one shape but in reality there are two shape. For your kind reference, I have attached the images as well. Please share, if I may help you further in this regard.

Many Thanks,