PptxGenJS icon indicating copy to clipboard operation
PptxGenJS copied to clipboard

defineSlideMaster() alters configuration object which causes lost placeholder formatting when reusing config object

Open ronnyroeller opened this issue 7 years ago • 1 comments

Issue

I'm using pptxgenjs 2.3.0. I create two PPTX files using the same shared slide master configuration, which contains a placeholder:

const PptxGenJS = require('pptxgenjs');

const SLIDE_MASTER = {
	title: 'SLIDE_MASTER',
	objects: [
		{
			placeholder: {
				options: {
					name: 'name',
					type: 'body',
					x: '20%',
					y: 2,
				},
			},
		},
	]
};

function createPptx(name) {
	const pptx = new PptxGenJS();

	pptx.defineSlideMaster(SLIDE_MASTER);

	const slide = pptx.addNewSlide('SLIDE_MASTER');
	slide.addText('Hello World1!', { placeholder: 'name' });

	pptx.save(name);
}

createPptx('Presentation1');
createPptx('Presentation2');

For the first run, the slide is correct:

image

For the second run, the slide lost its formatting:

image

Elements in the master slides without placeholders are not effected by this.

Workaround

Create a deep copy of the slide master configuration before passing it to defineSlideMaster:

pptx.defineSlideMaster(JSON.parse(JSON.stringify(SLIDE_MASTER)));

ronnyroeller avatar Sep 19 '18 10:09 ronnyroeller

I was just burned by this bug.

In src/gen-objects.ts, method createSlideMaster() deletes keys from the passed props of every placeholder. You can't reuse a placeholder slide definition. Was this a hack to get the media demo to work?

BasilaryGroup avatar Jan 15 '22 03:01 BasilaryGroup