I'm using the node module in a Sails.js project.
The first time I generate a PPT, everything looks good. When I generate a second PPT, the output file contains both presentations. A third call to .save() will produce a file with all three presentations.
I've tried requiring the module each time my generating method is called instead of a single time at the top of the file, but that's not working.
Is the library caching the last presentation? Is there any way to clear it?
Hi @alexanderpepper
Thanks for opening an issue. I was not able to reproduce this, however, I was using the same name for the output file which I can see might cause the Zip library to append instead of creating a new one.
I've now added a timestamp to the output filename so that this situation will be avoided.
Let me know if the issue persists.
Hi @gitbrent
Thanks for looking into it. I've tried using different filename and also tried deleting the old PPT before generating the new one. Neither worked.
Here's a Node script that reproduces the issue (and possibly another issue).
var pptx1 = require('pptxgenjs');
var slide = pptx1.addNewSlide();
slide.addText('Hello World!', { x:1.5, y:1.5, font_size:18, color:'363636' });
pptx1.save('Sample Presentation 1');
var pptx2 = require('pptxgenjs');
var slide2 = pptx2.addNewSlide();
slide.addText('Hello Again!', { x:1.5, y:1.5, font_size:18, color:'9A0000' });
pptx2.save('Sample Presentation 2');
Hi @alexanderpepper
I also had this issue and fixed it by invalidating cache.
delete require.cache[require.resolve('pptxgenjs')];
pptx1 = require('pptxgenjs');
That should solve your issue.
Excellent. That fixed it. Thanks @shivampadaliya
Ohhh, I completely misunderstood what you @alexanderpepper reported.
This is the expected behavior. The act of saving a Presentation doesn't automatically clear all the existing Slides, which is what is sounds like you were expecting. You can continue to .add* lots of things to the same pptx variable instance and it'll continue to accumulate Slides.
In order to generate new, unique Presentations, one would just grab a new instance of the library, which is what @shivampadaliya 's solution provides.
var pptx = new PptxGenJS();
pptx.addNewSlide().addText('pres 1', {x:1, y:1});
pptx.save('PptxGenJS-Sandbox-1');
// "Reset" pptx
pptx = new PptxGenJS();
pptx.addNewSlide().addText('pres 2', {x:1, y:1});
pptx.save('PptxGenJS-Sandbox-2');
Thanks to you both for reporting this and helping document the behavior.
I've made a reset function to reset the pptx object like this:
this.reset = function() {
gObjPptx = {};
gObjPptx.title = 'PptxGenJS Presentation';
gObjPptx.fileName = 'Presentation';
gObjPptx.fileExtn = '.pptx';
gObjPptx.pptLayout = LAYOUTS['LAYOUT_16x9'];
gObjPptx.slides = [];
};
and call this function to reset the last generated ppt...
This works if you do it on client with Angular for example;
import pptx from "pptxgenjs";
let PptxGenJS=Object.getPrototypeOf(pptx).constructor;
let presentation=new PptxGenJS();
It resets the object
This issue is resolved now (v 2.0.0).
See Issue #83