Open harishankar0301 opened 4 years ago
Interesting @harishankar0301 you are right i would expect the size of the file to drop. Wonder if we're hanging onto the deleted slides in memory somewhere. @gregdolley what do you think?
Is what I have done the proper way to remove slide and save the modified presentation.
@heavysixer @harishankar0301 - the removing slide code looks fine. That is indeed strange behavior. I'll take a look at it today.
As for your other question regarding moving a slide to a different pptx - unfortunately no, that way won't work. The source and destination pptx must be the same.
When I followed the logic I've said before to remove slides, the size of the created presentations doesn't decrease. But the interesting part is when I open the presentation that is created from the program in MS Powerpoint and then do a simple 'Save As' it saves a presentation with reduced size.
The previous logic:
const PPTX = require('node-pptx');
let pptx = new PPTX.Composer();
await pptx.load('./sample.pptx')
await pptx.compose(async pres => {
pres.removeSlide(pres.getSlide('slide1'));
});
await pptx.save('./test.pptx');
FYI after running this code, we have a new presentation test.pptx without slide1 but the size isn't reduced. When I open test.pptx in MS Powerpoint and do a simple Save As within powerpoint, the size got reduced to the correct size expected. Any thoughts on this?
I also tried to somehow make the process as a program , just load it and then save it but that didn't work, still the size didn't reduce. The only way was to manually open it in MS powerpoint and then do a save within powerpoint.
await pptx.load(`./test.pptx`);
await pptx.save(`./test_reduced.pptx`);
Any thoughts on how to achieve this reduction in size within the program itself eliminating the manual process. Regards,
I think its not removing unused media parts when removing slides. Is there a way to programatically compact pptx files and remove unreferenced media parts. I believe the issue is; the media used by the slide is not getting removed when we do
pres.removeSlide(pres.getSlide('slide1'));
Is there a way to keep only the media need for the slides present. Thanks in advance.
@harishankar0301 thank you for the sleuthing! I think we probably need a better way to prune the meta data when a slide (or other object) is removed from the document graph.
@harishankar0301 @heavysixer Yup, sorry I forgot to update the status on this. It is due to the unused media not getting removed when slides which reference that media are removed. I've confirmed this in my debugging/testing. I'm adding this to our TODO list.
@gregdolley would this be as simple as iterating over the elements array with an slide?
I know that we specify bidirectional relationships per the spec but it's unclear in reading if there is a clear parent child relationship in those linkages. It would be bad for example to loop over the relationships array and delete the associated entities because you could delete a slide layout for example.
When I remove the slides from a presentation of size 10MB with 5 slides, the resulting presentation is also 10MB. Even after removing 4 of the 5 slides, its still 10MB.
It would be nice if the size decreased with reducing slides. Please correct me if I'm making a mistake. And is there a way to ADD slides from existing presentation to another presentation. Something like this...