Manage Presentation Headers and Footers in JavaScript

Overview

PowerPoint uses different header and footer placeholders depending on the page type. Aspose.Slides for Node.js via Java 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 setFooterText and setDateTimeText to set text, and use setFooterVisibility, setDateTimeVisibility, and setSlideNumberVisibility 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:

const slides = require("aspose.slides.via.java");

const presentation = new slides.Presentation("presentation.pptx");
try {
    for (let i = 0; i < presentation.getSlides().size(); i++) {
        const slide = presentation.getSlides().get_Item(i);
        const headerFooterManager = slide.getHeaderFooterManager();

        headerFooterManager.setFooterText("Company Confidential");
        headerFooterManager.setFooterVisibility(true);

        headerFooterManager.setDateTimeText("Date and time text");
        headerFooterManager.setDateTimeVisibility(true);

        headerFooterManager.setSlideNumberVisibility(true);
    }

    presentation.save("presentation_with_slide_footers.pptx", slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

If you need to update only one slide, access that slide directly through the getSlides method 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:

const slides = require("aspose.slides.via.java");

const presentation = new slides.Presentation("presentation.pptx");
try {
    const masterNotesSlide = presentation.getMasterNotesSlideManager().getMasterNotesSlide();

    if (masterNotesSlide !== null) {
        const headerFooterManager = masterNotesSlide.getHeaderFooterManager();

        headerFooterManager.setHeaderText("Notes header");
        headerFooterManager.setHeaderVisibility(true);

        headerFooterManager.setFooterText("Notes footer");
        headerFooterManager.setFooterVisibility(true);

        headerFooterManager.setDateTimeText("Date and time text");
        headerFooterManager.setDateTimeVisibility(true);

        headerFooterManager.setSlideNumberVisibility(true);
    }

    presentation.save("presentation_with_notes_master_footers.pptx", slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

The getMasterNotesSlide method returns null when the presentation does not contain a notes master.

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, setHeaderAndChildHeadersText and setHeaderAndChildHeadersVisibility update the notes master header and all child headers. Equivalent methods are available for footers, date/time, and slide numbers.

const slides = require("aspose.slides.via.java");

const presentation = new slides.Presentation("presentation.pptx");
try {
    const masterNotesSlide = presentation.getMasterNotesSlideManager().getMasterNotesSlide();

    if (masterNotesSlide !== null) {
        const headerFooterManager = masterNotesSlide.getHeaderFooterManager();

        headerFooterManager.setHeaderAndChildHeadersText("Notes header");
        headerFooterManager.setHeaderAndChildHeadersVisibility(true);

        headerFooterManager.setFooterAndChildFootersText("Notes footer");
        headerFooterManager.setFooterAndChildFootersVisibility(true);

        headerFooterManager.setDateTimeAndChildDateTimesText("Date and time text");
        headerFooterManager.setDateTimeAndChildDateTimesVisibility(true);

        headerFooterManager.setSlideNumberAndChildSlideNumbersVisibility(true);
    }

    presentation.save("presentation_with_child_notes_footers.pptx", slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

The propagation methods used above are setFooterAndChildFootersText, setFooterAndChildFootersVisibility, setDateTimeAndChildDateTimesText, setDateTimeAndChildDateTimesVisibility, and setSlideNumberAndChildSlideNumbersVisibility.

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 addNotesSlide 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:

const slides = require("aspose.slides.via.java");

const presentation = new slides.Presentation("presentation.pptx");
try {
    const slide = presentation.getSlides().get_Item(0);
    const headerFooterManager = slide.getNotesSlideManager().addNotesSlide().getHeaderFooterManager();

    headerFooterManager.setHeaderText("Header for the first notes page");
    headerFooterManager.setHeaderVisibility(true);

    headerFooterManager.setFooterText("Footer for the first notes page");
    headerFooterManager.setFooterVisibility(true);

    headerFooterManager.setDateTimeText("Date and time text");
    headerFooterManager.setDateTimeVisibility(true);

    headerFooterManager.setSlideNumberVisibility(true);

    presentation.save("presentation_with_custom_notes_footers.pptx", slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

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 getMasterHandoutSlide to access the handout master. If it is not present, call setDefaultMasterHandoutSlide to create the default handout master.

const slides = require("aspose.slides.via.java");

const presentation = new slides.Presentation("presentation.pptx");
try {
    let masterHandoutSlide = presentation.getMasterHandoutSlideManager().getMasterHandoutSlide();

    if (masterHandoutSlide === null) {
        masterHandoutSlide = presentation.getMasterHandoutSlideManager().setDefaultMasterHandoutSlide();
    }

    if (masterHandoutSlide !== null) {
        const headerFooterManager = masterHandoutSlide.getHeaderFooterManager();

        headerFooterManager.setHeaderText("Handout header");
        headerFooterManager.setHeaderVisibility(true);

        headerFooterManager.setFooterText("Handout footer");
        headerFooterManager.setFooterVisibility(true);

        headerFooterManager.setDateTimeText("Date and time text");
        headerFooterManager.setDateTimeVisibility(true);

        headerFooterManager.setSlideNumberVisibility(true);
    }

    presentation.save("presentation_with_handout_footers.pptx", slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

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, isFooterVisible reports whether a footer placeholder is present, and setFooterVisibility changes its visibility.

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

Call the presentation’s setFirstSlideNumber method. 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.