officefileapi-405532-presentation-api-footers.md
Presentation slides can display a footer with footer text, date, and slide number. The DevExpress Presentation Library API allows you to add, edit, and remove these footer sections.
You can customize the footer of a master slide layout or individual slide.
You can use the SlideMaster object to specify a footer in a slide master layout. The following placeholder shapes are available:
ActualDateTimePlaceholderObtains the date and time placeholder shape.ActualFooterPlaceholderRetrieves placeholder shape for footer text.ActualSlideNumberPlaceholderGets slide number’s placeholder shape.ActualNotesPlaceholderObtains placeholder shape for slide notes.
To specify display text in each placeholder shape, use the TextAreaBase.Text property.
The following code snippet specifies content for footer text and date/time sections in the slide master layout:
using DevExpress.Docs.Presentation;
//...
using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\presentation1.pptx"))) {
SlideMaster slideMaster = presentation.SlideMasters[0];
slideMaster.ActualDateTimePlaceholder.TextArea.Text = DateTime.Now.ToString("dddd dd MMMM yyyy");
slideMaster.ActualFooterPlaceholder.TextArea.Text = "Created by DevExpress Presentation API";
presentation.SaveDocument(new FileStream("C://Documents//presentation-updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite));
}
Imports DevExpress.Docs.Presentation
'...
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\presentation1.pptx"))
Dim slideMaster As SlideMaster = presentation.SlideMasters(0)
slideMaster.ActualDateTimePlaceholder.TextArea.Text = Date.Now.ToString("dddd dd MMMM yyyy")
slideMaster.ActualFooterPlaceholder.TextArea.Text = "Created by DevExpress Presentation API"
presentation.SaveDocument(New FileStream("C://Documents//presentation-updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
End Using
The HeaderFooterManager class allows you to add footer text, date, and slide numbers to its associated presentation.
Obtain a Slide from the Presentation.Slides collection and pass it to the HeaderFooterManager.Add...Placeholder method to add a footer section to the slide.
Pass a list of Slide objects as the method parameter to display footers on multiple slides.
The following code snippet adds footer text, date and time, and a slide number to the first slide:
using DevExpress.Docs.Presentation;
//...
using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\presentation.pptx"))) {
var firstSlide = presentation.Slides[0];
var headerFooterManager = presentation.HeaderFooterManager;
headerFooterManager.AddFooterPlaceholder(firstSlide, "Created with DevExpress Presentation API");
headerFooterManager.AddSlideNumberPlaceholder(firstSlide);
headerFooterManager.AddDateTimePlaceholder(firstSlide, DateTime.Now.ToString());
presentation.SaveDocument(new FileStream("C://Documents//presentation_updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite));
}
Imports DevExpress.Docs.Presentation
'...
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\presentation.pptx"))
Dim firstSlide = presentation.Slides(0)
Dim headerFooterManager = presentation.HeaderFooterManager
headerFooterManager.AddFooterPlaceholder(firstSlide, "Created with DevExpress Presentation API")
headerFooterManager.AddSlideNumberPlaceholder(firstSlide)
headerFooterManager.AddDateTimePlaceholder(firstSlide, Date.Now.ToString())
presentation.SaveDocument(New FileStream("C://Documents//presentation_updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
End Using
Use the following properties to obtain footer placeholders of an individual slide (obtained by the Presentation.Slides property) or a slide master layout (obtained by the Presentation.SlideMasters property):
ActualDateTimePlaceholderObtains the date and time placeholder shape.ActualFooterPlaceholderRetrieves the footer text placeholder shape.ActualSlideNumberPlaceholderGets the slide number placeholder shape.
To specify placeholder shape content, use the TextAreaBase.Text property.
Note
A shape’s default character formatting settings may not produce consistent results across different presentation viewers. To ensure consistent appearance, specify character formatting settings explicitly in code.
The following code snippet customized the footer on the third slide (specifies font color for footer text and slide number, outlines the date and time shape):
using DevExpress.Docs;
using DevExpress.Docs.Presentation;
using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\presentation.pptx"))) {
var slide = presentation.Slides[2];
slide.ActualDateTimePlaceholder.Outline = new LineStyle { Fill = new SolidFill(Color.Green), Width = 4 };
var textArea = slide.ActualFooterPlaceholder.TextArea;
ParagraphProperties textParagraphProperties = new ParagraphProperties() {
TextProperties = new TextProperties() {
HighlightColor = new OfficeColor(Color.Red)
}
};
textArea.ParagraphProperties = textParagraphProperties;
textArea.Level1ParagraphProperties = textParagraphProperties;
presentation.SaveDocument(new FileStream("C://Documents//presentation_updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite));
}
Imports DevExpress.Docs
Imports DevExpress.Docs.Presentation
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\presentation.pptx"))
Dim slide = presentation.Slides(2)
slide.ActualDateTimePlaceholder.Outline = New LineStyle With {
.Fill = New SolidFill(Color.Green),
.Width = 4
}
Dim textArea = slide.ActualFooterPlaceholder.TextArea
Dim textParagraphProperties As ParagraphProperties = New ParagraphProperties() With {
.TextProperties = New TextProperties() With {
.HighlightColor = New OfficeColor(Color.Red)
}
}
textArea.ParagraphProperties = textParagraphProperties
textArea.Level1ParagraphProperties = textParagraphProperties
presentation.SaveDocument(New FileStream("C://Documents//presentation_updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
End Using
Call the Shapes.Remove method for the placeholder shape to remove a footer section from the slide.
The following code snippet removes the slide number from the first slide:
using DevExpress.Docs.Presentation;
//...
using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx"))) {
var slide = presentation.Slides[0];
while (slide.ActualFooterPlaceholder != null)
{
slide.Shapes.Remove(slide.ActualFooterPlaceholder);
}
presentation.SaveDocument(new FileStream("C://Documents//presentation_updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite));
}
Imports DevExpress.Docs.Presentation
'...
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
Dim slide = presentation.Slides(0)
Do While slide.ActualFooterPlaceholder IsNot Nothing
slide.Shapes.Remove(slide.ActualFooterPlaceholder)
Loop
presentation.SaveDocument(New FileStream("C://Documents//presentation_updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
End Using