This article guides on how to delete notes from PowerPoint with Java REST API. You will learn how to delete all notes in PowerPoint with Java Low Code API using a Java-based cloud SDK. It will provide you with a sample code for deleting a note slide and then confirmation of note deletion.
Prerequisite
- Create an account API credentials
- Download Aspose.Slides Cloud SDK for Java to delete a note
- Setup Java project with the above SDK for removing notes
Steps to Remove All Notes from PowerPoint with Java REST API
- Initialize the API client using the SlidesApi class with credentials for removing notes
- Upload the presentation with notes in it using the UploadFile() method
- Call the DeleteNotesSlide() method using the uploaded file name and target slide number
- Display the message to show that notes are deleted from the target slide
- Download the updated presentation after deleting the notes
These steps describe how to delete notes in PowerPoint with Java REST Interface. Upload the target presentation to the cloud storage and call the DeleteNotesSlide() method by providing the file name and target slide. Repeat this process for all the slides in the presentation and save the output on the disk.
Code to Delete All Notes in PowerPoint with Java REST Interface
package KbExamples; | |
import com.aspose.slides.ApiException; | |
import com.aspose.slides.api.SlidesApi; | |
import com.aspose.slides.model.Slide; | |
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_DeleteNotesInPresentation { | |
protected static SlidesApi presentationApi; | |
public Example_DeleteNotesInPresentation() { | |
if (presentationApi == null) { | |
presentationApi = new SlidesApi("appSid", "appKey"); | |
} | |
} | |
public void removeSlideNotes() throws ApiException, IOException { | |
String localPath = "/home/downloads/"; | |
String fileName = "Sample.pptx"; | |
String storageFolderName = "TempTests"; | |
presentationApi.uploadFile(storageFolderName+"/"+fileName, readFileToByteArray(localPath + fileName),null); | |
// Specify the slide index to modify (changed to slide 2) | |
int targetSlideNumber = 2; | |
// delete the notes slide from the specified slide | |
Slide updatedSlide = presentationApi.deleteNotesSlide(storageFolderName+"/"+fileName, targetSlideNumber, null, null, storageFolderName); | |
// Check if the notes slide exists after the operation | |
boolean isNotesSlidePresent = updatedSlide.getNotesSlide() != null; | |
System.out.println("Notes slide present: " + isNotesSlidePresent); | |
// Download the updated presentation from the server | |
File presentationFile = presentationApi.downloadFile(storageFolderName+"/"+fileName, null, null); | |
// Copy the downloaded presentation with removed comments to the local directory | |
copyFile(presentationFile, new File(localPath, fileName)); | |
System.out.println("Presentation with removed slide notes is 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 has demonstrated how to delete notes in PowerPoint with Java REST Interface. You can use the NotesSlide flag to check if some slide has notes in them before and after deleting the notes. To check the existence of the note slide, use the NotesSlideExists() method.
This article has taught us how to remove notes. For adding notes to a presentation, refer to the article on Add Notes to PowerPoint Slide with Java REST API.