Add Notes to PowerPoint Slide with Java REST API

This guide contains information on how to add notes to PowerPoint slides with Java REST API. You will learn to automatically add speaker notes to PowerPoint with Java RESTful Service using a Java-based Cloud SDK. A complete sample code is also part of this article demonstrating how to upload a presentation, perform desired operations, and download the updated presentation.

Prerequisite

Steps to Add Notes on PowerPoint with Java Low Code API

  1. Create the SlidesApi object with ID and secret for adding speaker notes
  2. Upload the presentation to the Cloud storage for inserting notes
  3. Create the NotesSlide object and set the text for the notes
  4. Call the CreateNotesSlide() method to insert notes
  5. Download the output file and save on the disk

These steps summarize how to add speaker notes in PowerPoint with Java RESTful Service. Create the SlidesApi object by providing the required parameters, upload the source presentation, and create the NotesSlide object with notes text. Finally, call the CreateNotesSlide() method to insert notes and download the updated presentation.

Code to Add Presentation Notes to PowerPoint with Java REST Interface

import com.aspose.slides.ApiException;
import com.aspose.slides.api.SlidesApi;
import com.aspose.slides.model.NotesSlide;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
public class Example_AddNotesInPresentation {
protected static SlidesApi presentationApi;
public Example_AddNotesInPresentation() {
if (presentationApi == null) {
presentationApi = new SlidesApi("appSid", "appKey");
}
}
public void addSlideNotes() throws ApiException, IOException {
String localPath = "/home/downloads/";
String fileName = "Sample.pptx";
String storageFolderName = "TempTests";
presentationApi.uploadFile(storageFolderName+"/"+fileName, readFileToByteArray(localPath + fileName),null);
NotesSlide notes = new NotesSlide ();
notes.setText("Here are the notes for the speaker");
// Add notes on the. third slide
NotesSlide currentNotesSlide = presentationApi.createNotesSlide(fileName, 3, notes, null, storageFolderName, null);
File presentationFile = presentationApi.downloadFile(storageFolderName+"/"+fileName, null, null);
// Copy the downloaded presentation with new comments to the local directory
copyFile(presentationFile, new File(localPath, fileName));
System.out.println("Presentation slide comment is set and copied to: " + localPath + fileName);
}
public static byte[] readFileToByteArray(String filePath) throws IOException {
Path path = new File(filePath).toPath();
return Files.readAllBytes(path);
}
private void copyFile(File sourceFile, File targetFile) throws IOException {
if (sourceFile == null || !sourceFile.exists()) {
throw new IOException("Source file does not exist: " + sourceFile);
}
// Ensure the target directory exists
Path targetPath = targetFile.toPath();
Files.createDirectories(targetPath.getParent());
// Copy the file
Files.copy(sourceFile.toPath(), targetPath, StandardCopyOption.REPLACE_EXISTING);
}
}

This code demonstrates how to insert notes in PowerPoint with Java based API. You may upload multiple presentations to the Cloud storage and provide the target presentation name where notes are to be added while calling the CreateNotesSlide method. Other parameters are the slide number and reference to the NotesSlide object created for the presentation.

This article has guided us in working with the presentation notes. To add animation to a PowerPoint slide, refer to the article on Animate PowerPoint slides with Java REST API.

 English