2

I want to create a pptx file with javascript and send it to the server. To do so, I am going to create a pptx file as blob.

Generating from the regular Client Browser, not Node.js. Below is the pptxGenjs site. https://gitbrent.githubio/PptxGenJS/docs/usage-save.html

The problem is not created as blob when pptx containing the image. When I print out a log on the console, only the name of pptx is shown. (It shall be printed on the console in the form of a blob.)

        ...
        var ppt_name = 'AAAA.pptx';

        var pptx = new PptxGenJS();
        pptx.setLayout('LAYOUT_4x3');
        pptx.defineSlideMaster({          
            title: 'MASTER_SLIDE',
            bkgd: 'FFFFFF',
            objects: [
                { 'text':  { text:'Writer', options:{ x:6.5, y:0.2, fontSize:8 } } },
                { 'text':  { text:'Date', options:{ x:8.0, y:0.2, fontSize:8 } } }
            ],
            slideNumber: {x: 0.3, y: '90%'}});
        var slide = pptx.addNewSlide('MASTER_SLIDE');

        slide.addImage({x: 0.5, y: 2.40, w: 2.67, h: 2.0, path:"/assets/main/AAA/AAA.png"});

        pptx.save(ppt_name, function(blob){console.log(blob);},'blob');
        ...

But when I changed last part of the same code, (Download .pptx by download prompt) image is well included in pptx. pptx.save(ppt_name);

and here is my console output.

When using slide.addimage

When slide.addimage is not used

What is the cause? Thanks!

  • 1
    Since you're using the library in the browser, I don't think it's possible to access the File System without having the user interact with a file Input element first. Try to encode the image as base64 and use a data URL instead of specifying a path. – fardjad Jul 25 '19 at 01:48
  • @fardjad Thank you for your response. By reference to your comments, I found this and I solved it! Thanks! https://stackoverflow.com/questions/6150289/how-to-convert-image-into-base64-string-using-javascript – happygreen17 Jul 25 '19 at 05:54

0 Answers0