Skip to content

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

@ronnyroeller

Description

@ronnyroeller

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)));

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions