Pptxgenjs: Using PptxGenJs in React

Created on 14 Mar 2018  路  6Comments  路  Source: gitbrent/PptxGenJS

Hi ,

How to import the pptxgenjs in the react app . i have installed it via npm . But not sure how to import it in the file .

I am getting the PptxGenJS() as undefined . i am using the version 2.0.0 .

Thanks .

angular documentation

Most helpful comment

This works in angular:

const PptxGenJS = require('pptxgenjs');
const pptx = new PptxGenJS();

pptx.setBrowser(true);

export function generatePPT() {
    const slide = pptx.addNewSlide();
    const opts = { x: 1.0, y: 1.0, font_size: 42, color: '00FF00' };
    slide.addText('Hello World!', opts);
    pptx.save();
}

All 6 comments

Hi @gitbrent , Any update on this ?

There's a couple Issues open for Angular/React at the moment, but i'm unable to produce a test case as i dont use either.

I use this in Node.js:
var pptx = require("pptxgenjs");

This works in angular:

const PptxGenJS = require('pptxgenjs');
const pptx = new PptxGenJS();

pptx.setBrowser(true);

export function generatePPT() {
    const slide = pptx.addNewSlide();
    const opts = { x: 1.0, y: 1.0, font_size: 42, color: '00FF00' };
    slide.addText('Hello World!', opts);
    pptx.save();
}

@sriganeshharitz Thanks man!

This also works in Vue!

I have tested it in React and it works as expected. I followed a similar approach to @sriganeshharitz by simply creating a generatePPI() method in the component and using an onClick handler which calls the method. If you have any trouble let me know and I can show my code.

Edit: As per the documentation it's also very important to include "pptx.setBrowser(true)" or you may run into some problems

Thanks everyone!

Example code and link to this Issue have been added to the API docs:

Library Integration

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jobnte picture jobnte  路  5Comments

simonjcarr picture simonjcarr  路  6Comments

sangramjagtap picture sangramjagtap  路  6Comments

Alexiz-Padilla picture Alexiz-Padilla  路  5Comments

readeral picture readeral  路  5Comments