This article guides how to remove watermark from presentation with Java REST API. You will learn how to remove watermark in PowerPoint with Java Low Code API using a couple of API calls in a Java-based SDK. The sample code will also demonstrate the creation of the output file from the API response.
Prerequisite
- Create an account API credentials
- Download Aspose.Slides Cloud SDK for Java to remove a watermark
- Setup Java project with the above SDK for deleting a watermark
Steps to Remove Watermark from PPT with Java REST API
- Create an instance of the SlidesApi class to remove the watermark
- Set the input and output presentation file names
- Read the input file into a memory stream
- Invoke the DeleteWatermarkOnline() method with input presentation file stream
- Save the memory stream in the response and save it on the local disk
These steps summarize how to remove watermark from PowerPoint with Java REST API. Load the input presentation into a stream and call the DeleteWatermarkOnline() method using the input stream. This API call returns the output stream that can be saved on the disk.
Code to Remove Watermark from PPT Online with Java RESTful Service
package KbExamples; | |
import com.aspose.slides.ApiException; | |
import com.aspose.slides.api.SlidesApi; | |
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_RemoveWatermarkInPresentation { | |
protected static SlidesApi presentationApi; | |
public Example_RemoveWatermarkInPresentation() { | |
if (presentationApi == null) { | |
presentationApi = new SlidesApi("appSid", "appKey"); | |
} | |
} | |
public void addWatermarkPictureInSlide() throws ApiException, IOException { | |
String localPath = "/home/downloads/"; | |
String fileName = "PresentationWithWatermark.pptx"; | |
String updatedPresentation = "CleanedPresentation.pptx"; | |
File presentationFile = presentationApi.deleteWatermarkOnline(readFileToByteArray(localPath + fileName),"watermarkShape", null); | |
// Copy the downloaded presentation with removed watermark to the local directory | |
copyFile(presentationFile, new File(localPath, fileName)); | |
System.out.println("Presentation slide with removed watermark is copied to: " + localPath + updatedPresentation); | |
} | |
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 remove watermark from PowerPoint slides with Java Java-based API. It removes the watermark from all the slides in the presentation. If the source presentation is password protected, use the password property in the API call to open the file to remove a watermark.
This article has taught us how to remove watermark from PPTX with Java REST API. To insert a watermark in a presentation, refer to the article on Add watermark to PPT with Java REST API.