Created
April 10, 2024 09:44
-
-
Save benheymink/2b06426c3d9374474775c080d40ec00a to your computer and use it in GitHub Desktop.
docx4j pptx loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PresentationMLPackage presentationMLPackage = | |
(PresentationMLPackage) OpcPackage.load(new java.io.File("src/resources/testPresentation.pptx")); | |
System.out.printf("Slide count: %d", presentationMLPackage.getMainPresentationPart().getSlideCount()); | |
MainPresentationPart mdp = presentationMLPackage.getMainPresentationPart(); | |
String notesFromSlide = mdp.getSlide(0).getNotesSlidePart().getContents().toString(); | |
System.out.printf("Slide 1 notes: %s", notesFromSlide); |
@plutext Sorry, should have been clearer - in this example some notes/content already exist, I'm simply trying to read them (and evenutally update them). I naively assumed the getContents
call would return the string contents, but I think i'm missing a step around wrangling the XML that method returns
Instead of getContents, try getXML()
Yes, that works (returns the XML). I'd then need to parse that XML correctly, I was looking for a lovely convenience feature to handle all of that for me :-) - i.e to get just the text contents of the notes, or to update the text of the slide notes. I'll keep digging...
(Thanks for the help btw!)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getNotesSlidePart() won't create the Notes part; it will return null if there isn't a notes part in the deck.
So you have to check for null.
There is method createNotesSlidePart(NotesMasterPart nmp)