I have a scenario where I need to copy few slides from a pptx (source.pptx) and download it as a separate pptx file (output.pptx) based on the presentation notes available in the slides. I am using apache poi to achieve it. This is my code.
String filename = filepath+"\\source.pptx";
try {
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(filename));
XMLSlideShow outputppt = new XMLSlideShow();
XSLFSlide[] slides = ppt.getSlides();
for (int i = 0; i < slides.length; i++) {
try {
XSLFNotes mynotes = slides[i].getNotes();
for (XSLFShape shape : mynotes) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape txShape = (XSLFTextShape) shape;
for (XSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) {
if (xslfParagraph.getText().equals("NOTES1") || xslfParagraph.getText().equals("NOTES2")) {
outputppt.createSlide().importContent(slides[i]);
}
}
}
}
} catch (Exception e) {
}
}
FileOutputStream out = new FileOutputStream("output.pptx");
outputppt.write(out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
When I open the output.pptx which is created, I am getting the following error: "PowerPoint found a problem with the content in output.pptx PowerPoint can attempt to repair the presentation If you trust the source of this presentation, click Repair."
Upon clicking repair: "PowerPoint removed unreadable content in merged.pptx [Repaired]. You should review this presenation to determine whether any content was unexpectedly changed or removed" And I can see blank slides with "Click to add Title" and "Click to add Subtitle"
Any suggestions to solve this issue?