首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在RequireJS中使用PptxGenJS

如何在RequireJS中使用PptxGenJS
EN

Stack Overflow用户
提问于 2020-04-21 04:48:52
回答 1查看 141关注 0票数 0

我已经尝试使用以下代码:

代码语言:javascript
复制
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‘文件,但是我不知道该怎么做。请给我建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-21 19:03:06

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

在查看了文档和源代码之后,我设法使其与RequireJS兼容。代码如下:

代码语言:javascript
复制
// 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');
    });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61331802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档