Header and footer in PowerPoint presentations are used to display additional information such as slide number, author, date, etc. In this article, you will learn how to add and manage the header and footer in PowerPoint PPTX/PPT presentations programmatically using C#.
- .NET API to Manage Header and Footer in PowerPoint
- Add Header and Footer in PowerPoint Presentation
- Manage Header and Footer in Handout and Notes Slide
.NET API to Manage Header and Footer in PowerPoint
In order to work with header and footer in PowerPoint presentations, we will use Aspose.Slides for .NET. It is a .NET class library that lets you create and manipulate PowerPoint and OpenOffice documents. You can download the API’s DLL from the downloads section. Also, the API can be installed via NuGet.
PM> Install-Package Aspose.Slides.NET
Add Header and Footer in PowerPoint using C#
The following are the steps to add header and footer in a PowerPoint presentation using C#.
- First, create a new presentation or load an existing one using Presentation class.
- Then, set footer using Presentation.HeaderFooterManager.SetAllFootersText(string) method.
- Access the master notes slide in an IMasterNotesSlide object using Presentation.MasterNotesSlideManager.MasterNotesSlide property.
- Loop through each shape in IMasterNotesSlide.Shapes collection.
- If IShape.Placeholder.Type is PlaceholderType.Header then set text for header using ((IAutoShape)shape).TextFrame.Text property.
- Finally, save the presentation using Presentation.Save(string, SaveFormat) method.
The following code sample shows how to add header and footer in a PowerPoint presentation.
Manage Header and Footer in Handout and Notes Slide using C#
Aspose.Slides for .NET also allows you to set the header and footer in handout and notes slides. For this, you can either apply changes in master notes slide or an individual slide. The following sections cover both scenarios.
Change Header and Footer Settings for Notes Master
- First, create a new presentation or load an existing one using Presentation class.
- Then, access the master notes slide in an IMasterNotesSlide object using Presentation.MasterNotesSlideManager.MasterNotesSlide property.
- Get reference of IMasterNotesSlideHeaderFooterManager from IMasterNotesSlide.HeaderFooterManager property.
- Update the header footer using IMasterNotesSlideHeaderFooterManager object.
- Finally, save the presentation using Presentation.Save(string, SaveFormat) method.
The following code sample shows how to change header and footer in notes master using C#.
Change Header and Footer Settings for Notes Slide
- First, create a new presentation or load an existing one using Presentation class.
- Then, access INotesSlide object of desired slide using Presentation.Slides[index].NotesSlideManager.NotesSlide property.
- Get reference of INotesSlideHeaderFooterManager from INotesSlide.HeaderFooterManager property.
- Update the header footer using INotesSlideHeaderFooterManager object.
- Finally, save the presentation using Presentation.Save(string, SaveFormat) method.
The following code sample shows how to change header and footer in notes slides using C#.
Get a Free API License
Get a free temporary license to use Aspose.Slides for .NET without evaluation limitations.
Conclusion
In this article, you have learned how to add header and footer in PowerPoint presentations using C#. Moreover, you have seen how to change header and footer in notes slides programmatically. Besides, you can explore the documentation to learn more about Aspose.Slides for .NET. Also, you can ask your questions via our forum.