0

I have tried with the following code:

require(['https://cdn.jsdelivr.net/gh/gitbrent/pptxgenjs@3.1.1/dist/pptxgen.bundle.js'], 
  (pptxgenjs) => {
  var pptx = new pptxgenjs();
  var slide = pptx.addSlide();
  slide.addText(
      "BONJOUR - CIAO - GUTEN TAG - HELLO - HOLA - NAMASTE - OLÀ - ZDRAS-TVUY-TE - こんにちは - 你好",
      { x:0, y:1, w:'100%', h:2, align:'center', color:'0088CC', fill:'F1F1F1', fontSize:24 }
  );
  pptx.writeFile('PptxGenJS-Demo');  
})

I think I might need to setup a 'require.config' file but I have no idea on how to do that. Please, advise.

Juanca
  • 3
  • 3

1 Answers1

0

When I tried to use the bundle version it didn't work - the pptx instance didn't have the addSlide() method.

After checking the docs and looking at the source code I've managed to make this compatible with RequireJS. Here is the code:

// first, require the dependency of PptxGenJs - JSZip
require(['https://cdn.jsdelivr.net/gh/gitbrent/pptxgenjs@3.1.1/libs/jszip.min.js'], (JSZip) => {
    // JSZip supports RequireJS but PptxGenJs needs it as global, so set it explicitly
    window.JSZip = JSZip;
    // here is your code, but instead of bundle fetch regular version
    require(['https://cdn.jsdelivr.net/gh/gitbrent/pptxgenjs@3.1.1/dist/pptxgen.min.js'], () => {
        var pptx = new PptxGenJS();
        var slide = pptx.addSlide();
        slide.addText(
            "BONJOUR - CIAO - GUTEN TAG - HELLO - HOLA - NAMASTE - OLÀ - ZDRAS-TVUY-TE - こんにちは - 你好",
            { x:0, y:1, w:'100%', h:2, align:'center', color:'0088CC', fill:'F1F1F1', fontSize:24 }
        );
        pptx.writeFile('PptxGenJS-Demo');
    });
});
Damian Dziaduch
  • 2,107
  • 1
  • 15
  • 16
  • Thanks Damian, it is working fine! According to your comments it is not possible to require both modules on the same require statement right? You first need to set the JSZip as global so that then you can require pptxgen. Thanks again! – Juanca Apr 21 '20 at 16:10
  • Yes, you are correct. You can mark my answer as correct :) – Damian Dziaduch Apr 21 '20 at 20:44