I created a ppt and try to stream it to the front end but it didnt work for me..
this is the server.js code
app.post("/generateppt", function(req, res) {
pptGeneratorO.generatePPT(req, res,function(data);
res.end();
});
this is the pptgenerator code
generatePPT: function( req , res ,callback)
{
var pptx = officegen(
{
type: 'pptx',
title: 'title',
}
);
// var pptName = 'out1.pptx';
res.writeHead ( 200, {
"Content-Type": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
'Content-disposition': 'attachment; filename=Summary.pptx'
});
// pptx.on ( 'finalize', function ( written ) {
// console.log ( 'Finish to create a PowerPoint file.\nTotal bytes created: ' + written + '\n' );
// });
// pptx.on ( 'error', function ( err ) {
// console.log ( err );
// });
// var pptName = fs.createWriteStream('output.pptx');
var slide = pptx.makeNewSlide ();
slide.addText('hai');
console.log('ppt is geenreated');
var out = fs.createWriteStream ( 'out.pptx' );
pptx.generate ( out, {
'finalize': function ( written ) {
console.log ( 'Finish to create a PowerPoint file.\nTotal bytes created: ' + written + '\n' );
},
'error': function ( err ) {
console.log ( err );
}
});
callback(res);
}
};
front end code
.post("/generateppt", {req: '', res: ''})
.then(function(response) {
console.log("saved successfully");
var pdfDoc = response.data;
var pdfBlob = new Blob([pdfDoc], { type: "application/vnd.openxmlformats-officedocument.presentationml.presentation" });
var pdfURL = window.URL.createObjectURL(pdfBlob);
var tempLink = document.createElement("a");
tempLink.href = pdfURL;
tempLink.setAttribute(
"download",
"Summary"
);
tempLink.setAttribute("target", "_blank");
document.body.appendChild(tempLink);
tempLink.click();
document.body.removeChild(tempLink);
});