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

Node module appends to last generated PPT on save() #38

Closed
alexanderpepper opened this issue Feb 9, 2017 · 8 comments
Closed

Node module appends to last generated PPT on save() #38

alexanderpepper opened this issue Feb 9, 2017 · 8 comments
Assignees
Milestone

Comments

@alexanderpepper
Copy link

alexanderpepper commented Feb 9, 2017

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?

@gitbrent gitbrent self-assigned this Feb 10, 2017
gitbrent pushed a commit that referenced this issue Feb 10, 2017
@gitbrent gitbrent added this to the v1.2.0 milestone Feb 10, 2017
@gitbrent
Copy link
Owner

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.

@alexanderpepper
Copy link
Author

alexanderpepper commented Feb 10, 2017

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');

@shivampadaliya
Copy link

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.

@alexanderpepper
Copy link
Author

Excellent. That fixed it. Thanks @shivampadaliya

@gitbrent
Copy link
Owner

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.

@gabriele-mastrapasqua
Copy link

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

@ArturFedorov
Copy link

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

@gitbrent
Copy link
Owner

This issue is resolved now (v 2.0.0).

See Issue #83

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

No branches or pull requests

5 participants