Skip to content
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

Open
coder-abhiwagh opened this issue May 31, 2020 · 6 comments
Open

Can't remove slide from presentation #55

coder-abhiwagh opened this issue May 31, 2020 · 6 comments
Assignees
Labels

Comments

@coder-abhiwagh
Copy link

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

@gregdolley
Copy link
Contributor

@abhiwagh I'll take a look.

@gregdolley
Copy link
Contributor

gregdolley commented Jun 26, 2020

@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.

@heavysixer
Copy link
Owner

heavysixer commented Jul 8, 2020

@gregdolley @abhiwagh ok to close this issue?

@harishankar0301
Copy link

@abhiwagh Is the size of the presentation decreasing when you remove the slides and save it?

@abdulloooh
Copy link

@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.

I followed this same approach and actually waited for the file to be loaded with then but nothing was removed from my file, what could be wrong please, I tried several pptx file but to no avail

@rajuy5697
Copy link

rajuy5697 commented May 25, 2023

const PPTX = require('nodejs-pptx');
let pptx = new PPTX.Composer();

async function load() {
await pptx.load('./Investment.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
pres.removeSlide(pres.getSlide(1));
});
}

load().then(() => removeSlide());

this is my code giving me error

node-pptx\node_modules\nodejs-pptx\lib\factories\doc-props\app.js:42
if (this.content['docProps/app.xml']['Properties']['Slides'] !== undefined) {
^

TypeError: Cannot read properties of undefined (reading 'Properties')

Any idea ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants