Masters & Placeholders
Create slides from named masters and pour text, images or charts into their placeholders.
DemoMaster
Source file Modules/DemoMaster.cs
Slide methods genSlide01 – genSlide06
Output files master_genSlide*.pptx
1Overview
DemoMaster shows the consumer side of the master system. Every method calls pptx.addSlide(new AddSlideProps { masterName = "…", sectionTitle = "Masters" }); the masters themselves are registered once by the test host (the PptxGen.js defineSlideMaster equivalent).
Placeholders are addressed by name: header, body, thanksText. Whatever you add with a matching placeholder option lands in that placeholder instead of floating at absolute coordinates.
2Demo methods
| Method | What it demonstrates |
|---|---|
| genSlide01 | TITLE_SLIDE — a slide bound to the title master. |
| genSlide02 | MASTER_SLIDE — a plain slide using the content master. |
| genSlide03 | Text placeholders — header plus pre-filled body bullets. |
| genSlide04 | Image placeholder — addImage routed into the body placeholder. |
| genSlide05 | Chart placeholder — a pie chart placed through the body placeholder. |
| genSlide06 | THANKS_SLIDE — text into the thanksText placeholder. |
3Code samples
Title master addSlide({ masterName: "TITLE_SLIDE" }). DemoMaster.cs · genSlide01
var slide = pptx.addSlide(new AddSlideProps { masterName = "TITLE_SLIDE", sectionTitle = "Masters" });
//var slide1 = pptx.addSlide(new AddSlideProps {MasterName = 'TITLE_SLIDE', SectionTitle = 'FAILTEST'}); // TEST = Should show console warning ("title not found")
slide.addNotes("Master name: `TITLE_SLIDE`\nAPI Docs: https://gitbrent.github.io/PptxGenJS/docs/masters.html");
}
Pre-filled text placeholders placeholder: "header" / "body"; body bullets are pre-filled. DemoMaster.cs · genSlide03
slide.addText("Text Placeholder", new TextPropsOptions { placeholder = "header" });
var texts = new List<TextProps> {
new TextProps { text = "Pre-filled placeholder bullets", options = new TextPropsOptions { bullet = true, valign = VAlign.top } },
new TextProps { text = "Add any text, charts, whatever", options = new TextPropsOptions { bullet = true, indentLevel = 1, color = "0000AB" } },
new TextProps { text = "Check out the online API docs for more", options = new TextPropsOptions { bullet = true, indentLevel = 2, color = "0000AB" } },
};
slide.addText(texts, new TextPropsOptions { placeholder = "body", valign = VAlign.top });
}
Image placeholder addImage into placeholder: "body", sized 12×5.25in. DemoMaster.cs · genSlide04
slide.addText("Image Placeholder", new TextPropsOptions { placeholder = "header" });
slide.addImage(new ImageProps {
placeholder = "body",
path = IMAGE_PATHS.starlabsBkgd.path,
w = 12.0,
h = 5.25,
});
}
Chart placeholder A pie chart dropped into the body placeholder. DemoMaster.cs · genSlide05
var dataChartPieLocs = new List<OptsChartData> {
new OptsChartData {
name = "Location",
labels = new List<List<string>> { new List<string> { "CN", "DE", "GB", "MX", "JP", "IN", "US" } },
values = new List<double?> { 69, 35, 40, 85, 38, 99, 101 },
},
};
var slide = pptx.addSlide(new AddSlideProps { masterName = "MASTER_SLIDE", sectionTitle = "Masters" });
slide.addNotes("Master name: `MASTER_SLIDE` using pre-filled placeholders\nAPI Docs: https://gitbrent.github.io/PptxGenJS/docs/masters.html");
slide.addText("Chart Placeholder", new TextPropsOptions { placeholder = "header" });
slide.addChart(ChartType.pie, dataChartPieLocs,
new ChartOpts { showLegend = true, legendPos = LegendPosition.l /* placeholder = "body" */ });
}
Content master addSlide({ masterName: "MASTER_SLIDE" }) — bare content master, no body content. DemoMaster.cs · genSlide02
var slide = pptx.addSlide(new AddSlideProps {
masterName = "MASTER_SLIDE",
sectionTitle = "Masters"
});
slide.addNotes("Master name: `MASTER_SLIDE`\nAPI Docs: https://gitbrent.github.io/PptxGenJS/docs/masters.html");
Thanks master addSlide({ masterName: "THANKS_SLIDE" }) + placeholder: "thanksText". DemoMaster.cs · genSlide06
var slide = pptx.addSlide(new AddSlideProps {
masterName = "THANKS_SLIDE",
sectionTitle = "Masters"
});
slide.addNotes("Master name: `THANKS_SLIDE`\nAPI Docs: https://gitbrent.github.io/PptxGenJS/docs/masters.html");
slide.addText("Thank You!", new TextPropsOptions { placeholder = "thanksText" });
4Key notes
The masters referenced here (TITLE_SLIDE, MASTER_SLIDE, THANKS_SLIDE) are registered once in the test host via the master-definition API, mirroring PptxGen.js defineSlideMaster.
placeholder accepts names such as "header", "body", "thanksText" — content added with placeholder: "…" is placed by the master layout, not by x/y coordinates.
Pre-filled placeholder bullets come from the body placeholder’s own content model — you fill the placeholder with any text list and it renders with the master styling.