Manage Presentation Headers and Footers with Python

Overview

PowerPoint uses different header and footer placeholders depending on the page type. Aspose.Slides for Python via .NET lets you control the text and visibility of these placeholders through header/footer manager classes.

The available placeholders depend on the scope:

Scope Header Footer Date/time Slide/page number
Regular slide No Yes Yes Yes
Notes master Yes Yes Yes Yes
Notes slide Yes Yes Yes Yes
Handout master Yes Yes Yes Yes

A regular presentation slide does not have a header placeholder. Headers are available on notes pages and handouts. For regular slides, use footer, date/time, and slide-number placeholders instead.

The scope of a change depends on the manager you use. The SlideHeaderFooterManager class controls one regular slide. The NotesSlideHeaderFooterManager class controls one notes slide. Master and layout managers can also propagate settings to dependent slides, while the MasterHandoutSlideHeaderFooterManager class controls the handout master.

For regular slides, the basic workflow is to access each slide’s header/footer manager, set the footer and date/time text, enable the required placeholders, and save the presentation. Slide numbers are generated by the presentation, so you only need to control their visibility.

Use set_footer_text and set_date_time_text to set text, and use set_footer_visibility, set_date_time_visibility, and set_slide_number_visibility to show the corresponding placeholders.

The following end-to-end example applies the same footer, date/time text, and slide-number visibility to all regular slides:

import aspose.slides as slides

with slides.Presentation("presentation.pptx") as presentation:
    for slide in presentation.slides:
        header_footer_manager = slide.header_footer_manager

        header_footer_manager.set_footer_text("Company Confidential")
        header_footer_manager.set_footer_visibility(True)

        header_footer_manager.set_date_time_text("Date and time text")
        header_footer_manager.set_date_time_visibility(True)

        header_footer_manager.set_slide_number_visibility(True)

    presentation.save("presentation_with_slide_footers.pptx", slides.export.SaveFormat.PPTX)

If you need to update only one slide, access that slide directly through the slides collection instead of iterating through the entire collection.

Set Headers and Footers on the Notes Master

The notes master defines common formatting and placeholder behavior for notes pages. Use the MasterNotesSlideHeaderFooterManager class when you want to change only the notes master itself.

The following example sets header, footer, and date/time text on the notes master and makes all supported placeholders visible on that master:

import aspose.slides as slides

with slides.Presentation("presentation.pptx") as presentation:
    master_notes_slide = presentation.master_notes_slide_manager.master_notes_slide

    if master_notes_slide is not None:
        header_footer_manager = master_notes_slide.header_footer_manager

        header_footer_manager.set_header_text("Notes header")
        header_footer_manager.set_header_visibility(True)

        header_footer_manager.set_footer_text("Notes footer")
        header_footer_manager.set_footer_visibility(True)

        header_footer_manager.set_date_time_text("Date and time text")
        header_footer_manager.set_date_time_visibility(True)

        header_footer_manager.set_slide_number_visibility(True)

    presentation.save("presentation_with_notes_master_footers.pptx", slides.export.SaveFormat.PPTX)

A presentation may not contain a notes master, so check the returned value for None before changing it.

Apply Notes Master Settings to Child Notes Slides

A notes master can apply header and footer settings to itself and to all dependent notes slides. Use the dedicated propagation methods on MasterNotesSlideHeaderFooterManager when the same settings should be applied across the notes hierarchy.

For example, set_header_and_child_headers_text and set_header_and_child_headers_visibility update the notes master header and all child headers. Equivalent methods are available for footers, date/time, and slide numbers.

import aspose.slides as slides

with slides.Presentation("presentation.pptx") as presentation:
    master_notes_slide = presentation.master_notes_slide_manager.master_notes_slide

    if master_notes_slide is not None:
        header_footer_manager = master_notes_slide.header_footer_manager

        header_footer_manager.set_header_and_child_headers_text("Notes header")
        header_footer_manager.set_header_and_child_headers_visibility(True)

        header_footer_manager.set_footer_and_child_footers_text("Notes footer")
        header_footer_manager.set_footer_and_child_footers_visibility(True)

        header_footer_manager.set_date_time_and_child_date_times_text("Date and time text")
        header_footer_manager.set_date_time_and_child_date_times_visibility(True)

        header_footer_manager.set_slide_number_and_child_slide_numbers_visibility(True)

    presentation.save("presentation_with_child_notes_footers.pptx", slides.export.SaveFormat.PPTX)

The propagation methods used above are set_footer_and_child_footers_text, set_footer_and_child_footers_visibility, set_date_time_and_child_date_times_text, set_date_time_and_child_date_times_visibility, and set_slide_number_and_child_slide_numbers_visibility.

Set Headers and Footers on an Individual Notes Slide

A notes slide belongs to a specific regular slide. Use its NotesSlideHeaderFooterManager class when you want to customize only that notes page.

The add_notes_slide method returns the notes slide for the current slide and creates one if it does not already exist. The following example configures the notes page associated with the first presentation slide:

import aspose.slides as slides

with slides.Presentation("presentation.pptx") as presentation:
    notes_slide = presentation.slides[0].notes_slide_manager.add_notes_slide()
    header_footer_manager = notes_slide.header_footer_manager

    header_footer_manager.set_header_text("Header for the first notes page")
    header_footer_manager.set_header_visibility(True)

    header_footer_manager.set_footer_text("Footer for the first notes page")
    header_footer_manager.set_footer_visibility(True)

    header_footer_manager.set_date_time_text("Date and time text")
    header_footer_manager.set_date_time_visibility(True)

    header_footer_manager.set_slide_number_visibility(True)

    presentation.save("presentation_with_custom_notes_footers.pptx", slides.export.SaveFormat.PPTX)

If you first propagate settings from the notes master and then change an individual notes slide, the later per-slide settings let you customize that notes page independently.

Set Headers and Footers on the Handout Master

Handout pages use the handout master for their header, footer, date/time, and page-number placeholders. Unlike notes pages, handout settings are managed through the handout master rather than through individual handout slides.

Use the master_handout_slide property to access the handout master. If it is not present, call set_default_master_handout_slide to create the default handout master.

import aspose.slides as slides

with slides.Presentation("presentation.pptx") as presentation:
    master_handout_slide = presentation.master_handout_slide_manager.master_handout_slide

    if master_handout_slide is None:
        presentation.master_handout_slide_manager.set_default_master_handout_slide()
        master_handout_slide = presentation.master_handout_slide_manager.master_handout_slide

    if master_handout_slide is not None:
        header_footer_manager = master_handout_slide.header_footer_manager

        header_footer_manager.set_header_text("Handout header")
        header_footer_manager.set_header_visibility(True)

        header_footer_manager.set_footer_text("Handout footer")
        header_footer_manager.set_footer_visibility(True)

        header_footer_manager.set_date_time_text("Date and time text")
        header_footer_manager.set_date_time_visibility(True)

        header_footer_manager.set_slide_number_visibility(True)

    presentation.save("presentation_with_handout_footers.pptx", slides.export.SaveFormat.PPTX)

Understand Scope and Inheritance

Choose the header/footer manager that matches the scope you want to change:

Use propagation from a master or layout when the same setting should apply throughout its hierarchy. Use an individual slide or notes-slide manager when you need a local setting for one page.

FAQ

Can I add a header to a regular slide?

No. PowerPoint does not define a header placeholder for regular slides. On regular slides, use the footer, date/time, and slide-number placeholders. Header placeholders are available on notes pages and handouts.

What if a footer, date/time, or slide-number placeholder is not visible?

Use the corresponding header/footer manager to check its visibility and enable it when needed. For example, is_footer_visible reports whether a footer placeholder is present, and set_footer_visibility changes its visibility.

How do I start slide numbering from a value other than 1?

Set the presentation’s first_slide_number property. The slide-number placeholders then use the updated numbering sequence.

What happens to headers and footers when exporting to PDF, images, or HTML?

Visible header and footer elements are rendered with the rest of the presentation content in the output format. Their appearance depends on the page type being exported and the corresponding placeholder visibility settings.