Welcome folks today in this blog post we will be using the officegen
library to generate powerpoint
files and adding text and images
in node.js and javascript. All the full source code of the application is shown below.
Get Started
In order to get started you need to make a new node.js
project using the below command as shown below
npm init -y
npm i officegen
npm i pptx
And after that you need to make a new index.js
file and copy paste the following code
index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
const officegen = require('officegen') const fs = require('fs') // Create a new PPTX file let pptx = officegen('pptx') // Add a new slide to the presentation const slide1 = pptx.makeNewSlide(); // Add text to the slide slide1.addText('Hello, world!'); // Create a new slide let slide2 = pptx.makeNewSlide(); // Add Image slide2.addImage('image.jpg') // Set save path let out = fs.createWriteStream('image.pptx') // Save pptx.generate(out) |
As you can see we are importing the xlsx
and officegen
library at the top and then we are adding a new slide
inside the powerpoint file using the makeNewSlide()
method. And then we are adding the text
using the addText()
method and then we are adding the image
using the addImage()
method. And then we are generating the pptx
file using the generate()
method.