-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't remove slide from presentation #55
Comments
@abhiwagh I'll take a look. |
@abhiwagh - The reason for this is because you're calling two async functions back-to-back before waiting for the first one to finish. So initially, when PPTX is instantiated, the pptx it has in memory is one with no slides, and when you call removeSlide() (before the load finishes) you're actually removing slide1 from the blank template, not the file you're trying to load (so the exception of "slide1" doesn't exist, is correct at that point in time). Instead, the code should be: load().then(() => removeSlide()); This ensures your file finishes loading in PPTX's internal structure, before you call removeSlide() on it. Now it won't crash. |
@gregdolley @abhiwagh ok to close this issue? |
@abhiwagh Is the size of the presentation decreasing when you remove the slides and save it? |
I followed this same approach and actually waited for the file to be loaded with |
const PPTX = require('nodejs-pptx'); async function load() { async function removeSlide() { load().then(() => removeSlide()); this is my code giving me error node-pptx\node_modules\nodejs-pptx\lib\factories\doc-props\app.js:42 TypeError: Cannot read properties of undefined (reading 'Properties') Any idea ? |
I am trying to remove slide from my presentation using code
`const PPTX = require('nodejs-pptx');
let pptx = new PPTX.Composer();
async function load() {
await pptx.load('/app/go/src/ppt2svgconverter/Node-PPTX/hello-world.pptx'); // load a pre-existing PPTX
}
async function removeSlide() {
await pptx.compose(pres => {
pres.removeSlide(pres.getSlide("slide1")); // remove the first slide from the PPTX
// OR ---> pres.removeSlide(pres.getSlide(1)); <--- example of getting a slide by intege
});
}
load();
removeSlide();`
But getting error like node:10115) UnhandledPromiseRejectionWarning: Error: Invalid slide name in Presentation.getSlide(): slide1
PPT I used is attached here
hello-world.pptx
The text was updated successfully, but these errors were encountered: