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 Java.
- Java API to Manage Header and Footer in PowerPoint
- Add Header and Footer in PowerPoint Presentation
- Manage Header and Footer in Handout and Notes Slide
Java 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 Java. It is a feature-rich API that lets you create and manipulate PowerPoint and OpenOffice documents. You can either download the API’s JAR or install it via Maven.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-slides</artifactId>
<version>21.9</version>
<classifier>jdk16</classifier>
</dependency>
Add Header and Footer in PowerPoint using Java
The following are the steps to add header and footer in a PowerPoint presentation using Java.
- First, create a new presentation or load an existing one using Presentation class.
- Then, set footer using Presentation.getHeaderFooterManager().setAllFootersText(String) method.
- Access the master notes slide in an IMasterNotesSlide object using Presentation.getMasterNotesSlideManager().getMasterNotesSlide() method.
- Loop through each shape in IMasterNotesSlide.getShapes() collection.
- If IShape.getPlaceholder().getType() is PlaceholderType.Header then set text for header using ((IAutoShape)shape).getTextFrame().setText() method.
- 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 Java
Aspose.Slides for Java 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.getMasterNotesSlideManager().getMasterNotesSlide() method.
- Get reference of IMasterNotesSlideHeaderFooterManager from IMasterNotesSlide.getHeaderFooterManager() method.
- 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 Java.
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.getSlides().get_Item(int index).getNotesSlideManager().getNotesSlide() method.
- Get reference of INotesSlideHeaderFooterManager from INotesSlide.getHeaderFooterManager() method.
- 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 Java.
Get a Free API License
Get a free temporary license to use Aspose.Slides for Java without evaluation limitations.
Conclusion
In this article, you have learned how to add header and footer in PowerPoint presentations using Java. 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 Java. Also, you can ask your questions via our forum.