Hi,
I’m trying to modify the attached presentation by clearing text from each paragraph’s portion collection and adding three new portions. The first one and the last one contain only the space character, while the middle one contains paragraph’s text. The problem occurs when I try to save the presentation. The action never completes.
Here’s the code I used:
IPresentation presentation = new Presentation("1.pptx");
ISlideCollection slides = presentation.getSlides();
for (ISlide slide : slides) {
IShapeCollection shapes = slide.getShapes();
for (IShape shape : shapes) {
if (shape instanceof IAutoShape) {
ITextFrame textFrame = ((IAutoShape) shape).getTextFrame();
if (textFrame != null) {
IParagraphCollection paragraphs = textFrame.getParagraphs();
for (IParagraph paragraph : paragraphs) {
String paragraphText = paragraph.getText();
IPortionCollection portions = paragraph.getPortions();
if (portions.getCount() > 0) {
IPortion formattingPortion = portions.get_Item(0);
portions.clear();
IPortion spacePortion = new Portion((Portion) formattingPortion);
spacePortion.setText(" ");
portions.add(spacePortion);
IPortion newPortion = new Portion((Portion) formattingPortion);
newPortion.setText(paragraphText);
portions.add(newPortion);
spacePortion = new Portion((Portion) formattingPortion);
spacePortion.setText(" ");
portions.add(spacePortion);
}
}
}
}
}
}
FileOutputStream outputStream = new FileOutputStream("1-aspose.pptx");
presentation.save(outputStream, SaveFormat.Pptx);
outputStream.close();
Environment info:
Ubuntu 16.04 x64
java version “1.8.0_161”
Thanks,
Zeljko
1.pptx.zip (2.4 MB)