Skip to content

New Report adding to previously created report #170

Closed
@kammetherell

Description

@kammetherell

I'm trying to create a PPT file using NodeJS, currently everytime I click the button on my page to generate the report, it just appends it to the previous output.

I'm calling var pptx = require("pptxgenjs") everytime, as per the instructions, so not sure what I'm doing wrong. Apologies I'm a bit of a newbie to this.

My Route that generates the report is

router.get("/", function(req,res) {     //middlewareObj.isLoggedIn, 
    Plan.findById(req.params.id).populate("planEntries").exec(function(err,foundPlan){   
        if(err){
            console.log(err);
        } else {
            var pptx = require("pptxgenjs");
                      
            // Define Slide Layout
            pptx.setLayout('LAYOUT_16x9');
            
            // Cover Slide
            var slide = pptx.addNewSlide();
                slide.color = '575756';
                slide.slideNumber({ x:0.5, y:'90%', font_size:8, font_face:'Arial', color: 'fff'})
                
                slide.addImage({
                    path: './public/images/SlideCover.png',
                    x:0, y:0, w: '100%', h: '100%'
                });
                
                slide.addText(foundPlan.name, { x:0.4, y:1.5, font_size:36, font_face:'Arial', color: '26478d'});
                slide.addText('Contributing Region: ' + foundPlan.contributingRegion + '; Start Year: ' + foundPlan.startYear, { x:0.4, y:2.2, font_size:12, font_face:'Arial'});
                
            // Slide 1
            var slide = pptx.addNewSlide();
                slide.color = '575756';
                slide.slideNumber({ x:0.5, y:'90%', font_size:8, font_face:'Arial', color: 'fff'})
                
            // Slide 2
            var slide = pptx.addNewSlide();
                slide.color = '575756';
                slide.slideNumber({ x:0.5, y:'90%', font_size:8, font_face:'Arial', color: 'fff'})
                
            // Save PPT
            pptx.save("http", function(data){
                var strFilename = foundPlan.name+".pptx";
                res.writeHead(200, { 'Content-disposition':'attachment;filename='+strFilename, 'Content-Length':data.length });
		        res.end(new Buffer(data, 'binary'));
            });
        }
    });
});

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions