Slide Master¶
Custom Slide Master¶
You can create custom slide masters by defining your own layout classes. Here's an example of how to create and use a custom slide master:
import datetime
import tppt
class CustomTitleSlideLayout(tppt.SlideLayout):
title: tppt.Placeholder[str]
subtitle: tppt.Placeholder[str | None] = None
date: tppt.Placeholder[datetime.date | None] = None
footer: tppt.Placeholder[str | None] = None
class CustomTitleAndContentSlideLayout(tppt.SlideLayout):
title: tppt.Placeholder[str]
content: tppt.Placeholder[str]
date: tppt.Placeholder[datetime.date | None] = None
footer: tppt.Placeholder[str | None] = None
@tppt.slide_master("custom_slide_master_base.pptx")
class CustomSlideMaster(tppt.SlideMaster):
TitleLayout: tppt.Layout[CustomTitleSlideLayout]
TitleAndContentLayout: tppt.Layout[CustomTitleAndContentSlideLayout]
presentation = (
tppt.Presentation.builder(CustomSlideMaster)
.slide(
lambda slide: slide.TitleLayout(
title="Custom Master Title",
)
)
.slide(
lambda slide: slide.TitleAndContentLayout(
title="Custom Title",
content="Custom Content",
)
.builder()
.text(
"Custom Text",
top=(1, "in"),
left=(2, "in"),
width=(3, "in"),
height=(4, "in"),
)
)
.build()
.save("custom_slide_master.pptx")
)
Automatic Template Generation¶
You can automatically generate slide master and layout definitions from an existing PowerPoint file using the ppt2template tool:
This will analyze your PowerPoint file and generate: - Custom layout classes for each slide layout - A slide master class that uses these layouts - Proper type hints for all placeholders
The generated code can be used directly in your project, saving you the effort of manually defining layouts and placeholders.
Features of Generated Templates¶
- Automatically detects placeholder types (title, content, date, footer, etc.)
- Generates appropriate field names and types
- Handles special cases like multiple content placeholders
- Maintains the original layout structure
- Provides type safety through proper type hints