0

我尝试过使用以下代码:

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');  
})

我想我可能需要设置一个“require.config”文件,但我不知道该怎么做。请指教。

4

1 回答 1

0

当我尝试使用该bundle版本时它不起作用 -pptx实例没有该addSlide()方法。

检查文档并查看源代码后,我设法使其与 RequireJS 兼容。这是代码:

// 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');
    });
});
于 2020-04-21T11:03:05.567 回答