Description
Hello guys,
Having some issues with updating the content of a slide and getting back the new elements from the resulting presentation.
What we use to update the slides is something like below
`
slides.forEach((slide) => {
const slideUpdates = updatesBySlide.get(slide.number);
if (slideUpdates) {
pres.addSlide(
`${fileName}-template`,
slide.number,
(slideObj: ISlide) => {
slideUpdates.forEach((update) => {
const shape = slide.elements.find(
(element) =>
element.name === update.name &&
Math.abs(element.position.x - update.emuPosition.x) < 1000 &&
Math.abs(element.position.y - update.emuPosition.y) < 1000 &&
Math.abs(element.position.cx - update.emuPosition.cx) <
1000 &&
Math.abs(element.position.cy - update.emuPosition.cy) < 1000
);
if (shape && shape.hasTextBody) {
slideObj.modifyElement(update.name, [
ModifyTextHelper.setText(update.textContent.join("\n")),
]);
}
});
}
);
} else {
// If no updates for this slide, still need to add it to maintain presentation structure
pres.addSlide(`${fileName}-template`, slide.number);
}
});
`
This seems to be working great and creating the correct pptx file when saving it like below
const outputPath = path.join(outputDir, fileName); await pres.write(fileName);
But when we try to pull out all the slides from the pptx with something like below:
`
const pres = automizer.load(fileName, `${fileName}-template`);
const presInfo = await pres.getInfo();
const slides = presInfo
.slidesByTemplate(`${fileName}-template`)
.map((slide) => {
const slideNumber = slide.number;
return {
number: slide.number,
name: slide.info.name,
shapes: slide.elements
.filter(
(shape) =>
shape.hasTextBody === true && shape.getText().length !== 0
)
.map((shape) => {
const text = shape.getText();
return {
name: shape.name,
type: shape.type,
text: text,
position: {
x: shape.position.x,
y: shape.position.y,
cx: shape.position.cx,
cy: shape.position.cy,
},
};
}),
};
});
`
What I find is that the below has double the number of slides than what I expect which I think partially makes sense just that I was expecting for the old slides to not be kept especially as we use removeExistingSlides: true
presInfo.slidesByTemplate(${fileName}-template
)
Any idea what am I misunderstanding?