heavysixer / node-pptx

Generate PPTX files on the server-side with JavaScript.
MIT License
164 stars 46 forks source link

Merging Specific slides from pre-existing powerpoints #134

Open Jcoumarb opened 4 months ago

Jcoumarb commented 4 months ago

I saw that it has been answered as to whether or not it is possible to achieve this with node-pptx but I have not seen any documentation with an example. I have attached my attempt at this solution and I get errors:

const pptx2 = require('nodejs-pptx');

async function merge () {
    let dynamic = new pptx2.Composer();
    await dynamic.load(`./ui/resources/generated.pptx`);

    let static = new pptx2.Composer();
    await static.load('./ui/resources/generated.pptx');

    let output = new pptx2.Composer();

    await output.compose(async pres => {
        pres.addSlide(dynamic.getSlide('slide1')); 
    });

    await pptx.save(`./ui/resources/completed.pptx`);
}

merge();

this is the error that I receive attached below. lines 294 and 295 of index.js correspond to 'await output.compose' and the line that follows:

C:\Users\coumarbj\work\pptxGen\job-soms-dashboard-presentation\node_modules\nodejs-pptx\lib\presentation.js:114
        await config(this.powerPointFactory.addSlide(layoutName || this.defaultSlideLayout));
              ^

TypeError: config is not a function
    at Presentation.addSlide (C:\Users\coumarbj\work\pptxGen\job-soms-dashboard-presentation\node_modules\nodejs-pptx\lib\presentation.js:114:15)
    at C:\Users\coumarbj\work\pptxGen\job-soms-dashboard-presentation\ui\index.js:295:14
    at Composer.compose (C:\Users\coumarbj\work\pptxGen\job-soms-dashboard-presentation\node_modules\nodejs-pptx\lib\composer.js:20:15)
    at merge (C:\Users\coumarbj\work\pptxGen\job-soms-dashboard-presentation\ui\index.js:294:18)

Node.js v22.2.0

I would also be satisfied if I could not select specific slides and I could load the entirety of the two source files and parse through with delete and re-order

Donny-H commented 3 weeks ago

Did you end up with a solution? This is my exact use case.