singerla / pptx-automizer

A template based pptx generator for Node.js
MIT License
68 stars 12 forks source link

Reorder and delete slide masters? #88

Closed jhaase1 closed 8 months ago

jhaase1 commented 9 months ago

Both these questions relate to operations that seem nearly possible given the functionality in ModifyPresentationHelper. Is it possible to

  1. Remove a specific slide master? This seems closely related to the removeUnusedFiles function
  2. Reorder slide master? This seems to be closely related to the sortSlides function.

This is trying to work around the inability to modify in place and replace the original version of the slide master with the new modified version.

singerla commented 9 months ago

I was playing around a bit with some modifications of ppt/presentation.xml.

You could try this:

  let pres = automizer
    .loadRoot(`RootTemplate.pptx`)
    .load(`SlideWithCharts.pptx`, 'charts');

  pres.addSlide('charts', 1, async (slide) => {
    // 
  });

  pres.modify((presXml: XmlDocument) => {
    const slideMasters =
      ModifyPresentationHelper.getSlideMastersCollection(presXml);

   // You can basically rearrange the slideMasters collection
    XmlHelper.sortCollection(slideMasters, [1, 0]);

   // And also remove slideMasters
    XmlHelper.sliceCollection(slideMasters, 1, 0);
  });

The problems are:

This is because of ModifyPresentationHelper.normalizeSlideMasterIds is not working properly when the first id was cut out (see currentId). The above should work if the first (unmodified) master is kept in place.

singerla commented 9 months ago

p:sldMasterId-ids and p:sldLayoutId-ids need to be in a row, otherwise PowerPoint will complain on any p:sldLayoutId-id lower than its corresponding slideMaster-id.