Skip to content

Commit 473bd0e

Browse files
authored
Merge pull request #93 from singerla/fix-slide-master-background-image
Fix slide master background image
2 parents f3b17ab + 51e971b commit 473bd0e

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

__tests__/add-slide-master-auto-import.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ test('Auto-import source slideLayout and -master', async () => {
1111
const pres = await automizer
1212
.loadRoot(`EmptyTemplate.pptx`)
1313
.load('SlidesWithAdditionalMaster.pptx')
14+
.load('SlideMasterBackgrounds.pptx')
1415
.load('SlideMasters.pptx')
1516

1617
// We can disable .addMaster according to "autoImportSlideMasters: true"
@@ -25,7 +26,8 @@ test('Auto-import source slideLayout and -master', async () => {
2526
.addSlide('SlidesWithAdditionalMaster.pptx', 1)
2627
.addSlide('SlideMasters.pptx', 3)
2728
.addSlide('SlideMasters.pptx', 2)
29+
.addSlide('SlideMasterBackgrounds.pptx', 2)
2830
.write(`add-slide-master-auto-import.test.pptx`);
2931

30-
expect(pres.masters).toBe(5);
32+
expect(pres.masters).toBe(6);
3133
});
55.1 KB
Binary file not shown.

src/classes/shape.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { XmlHelper } from '../helper/xml-helper';
2-
import { GeneralHelper } from '../helper/general-helper';
2+
import { GeneralHelper, vd } from '../helper/general-helper';
33
import {
44
ChartModificationCallback,
55
ImportedElement,
@@ -174,12 +174,16 @@ export class Shape {
174174
);
175175
}
176176

177+
/*
178+
* This will find all elements with a matching rId on a
179+
* <p:cSld>, including related images at <p:bg> and <p:spTree>.
180+
*/
177181
async getElementsByRid(
178182
slideXml: XmlDocument,
179183
rId: string,
180184
): Promise<XmlElement[]> {
181185
const sourceList = slideXml
182-
.getElementsByTagName('p:spTree')[0]
186+
.getElementsByTagName('p:cSld')[0]
183187
.getElementsByTagName(this.relRootTag);
184188

185189
const sourceElements = XmlHelper.findByAttributeValue(

src/dev.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ const run = async () => {
55
const automizer = new Automizer({
66
templateDir: `${__dirname}/../__tests__/pptx-templates`,
77
outputDir: `${__dirname}/../__tests__/pptx-output`,
8-
removeExistingSlides: true,
8+
autoImportSlideMasters: true,
99
});
1010

1111
let pres = automizer
12-
.loadRoot(`SlidesWithoutCreationIds.pptx`)
13-
.load(`SlideWithCharts.pptx`, 'noCreationId');
12+
.loadRoot(`RootTemplate.pptx`)
13+
.load(`SlideMasterBackgrounds.pptx`);
1414

15-
pres.addSlide('noCreationId', 1, async (slide) => {
16-
// const elements = await slide.getAllElements();
17-
// const textElements = await slide.getAllTextElementIds();
18-
vd(await slide.getDimensions());
15+
pres.addSlide(`SlideMasterBackgrounds.pptx`, 2, async (slide) => {
16+
console.log('test');
1917
});
2018

21-
pres.write(`myOutputPresentation.pptx`).then((summary) => {
19+
pres.write(`SlideMasterBackgroundsOutput.pptx`).then((summary) => {
2220
console.log(summary);
2321
});
2422
};

src/types/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ export type AutomizerParams = {
6262
presTemplates?: string[];
6363
useCreationIds?: boolean;
6464
/**
65-
* If you have trouble with messed up slideMasters, and if you don't worry
66-
* about the impact on performance, you can try this to always import all
67-
* required files:
65+
* Turn this to true if you always want to import all required slide masters.
66+
* You don't need to adjust with slide.useSlideLayout, but it will have a
67+
* negative impact on performance.
68+
* It is highly recommended to activate autoImportSlideMasters in case your
69+
* loaded templates have different sets of slideMasters & -layouts.
6870
*/
6971
autoImportSlideMasters?: boolean;
7072
/**

0 commit comments

Comments
 (0)