For the protection of the documents and presentations from illegal use, we can use watermarking. In this article, we will learn to programmatically apply text and image-based watermarks to the presentations or specific slides of a presentation in Java. In another post, we have discussed applying watermarks to presentations using C#.
The following topics will be covered below:
- Java Watermarking API
- Add text watermarks to presentation slides
- Add image watermarks to presentation slides
Java Watermarking API for Presentations
GroupDocs.Watermark provides the Java API for watermarking, which allows adding text and image watermarks to the presentations within your application.
Alongside the presentations, the API supports adding, removing, and extracting watermarks from word-processing documents, spreadsheets, email messages, PDF files, images, and many other formats.
Download and Configure
You can get the watermarking library from the downloads section. For Maven-based Java applications, just add the following pom.xml configuration. Afterward, you can try watermarking examples of this article as well as many more examples from GitHub. For the details, you may visit the API Reference.
<repository> <id>GroupDocsJavaAPI</id> <name>GroupDocs Java API</name> <url>http://repository.groupdocs.com/repo/</url> </repository>
<dependency> <groupId>com.groupdocs</groupId> <artifactId>groupdocs-watermark</artifactId> <version>21.3</version> </dependency>
Add Text Watermark to Presentation Slides in Java
Using the API, you can apply customizations while adding text to presentation slides as a watermark. The following steps show how to apply watermark on presentations within the Java application.
- Load the presentation using Watermarker.
- Set watermark text and style using TextWatermark.
- Set watermark properties like size, location, opacity, rotation, and color.
- Provide the slide index on which to apply the watermark. (Optional)
- Add the formatted text watermark using the add method.
- Save the watermarked presentation by calling the save method.
The following code sample shows how to add a text watermark in PPT or PPTX on all the slides with rotation using Java.
If the slide index is not set, the watermark will be applied to all the slides of the presentation by default. The above code also shows how to mention the slide index. The following output with a text watermark on all the slides of the PPTX presentation.
Add Image Watermark to PPT Slides using Java
You can add image watermarks on the presentation files as well with a similar approach. Just use the ImageWatermark class instead of the TextWatermark.
The following steps guide how to add image watermark to presentation slides within your Java applications.
- Load the presentation file.
- Load the image, logo, or photo that will be used as an image watermark.
- Set image watermark properties like rotation, size, opacity, color, and position.
- Set the slide index on which the watermark will be applied.
- Add the image watermark to the presentation.
- Save the presentation with the image watermark.
The following code sample adds an image to the PPTX presentation as an image watermark on the second slide in Java.
The following is the output of the code with an image watermark only on the second slide of the PPT/PPTX.
Get a Free API License
You can get a free temporary license in order to use the API without the evaluation limitations.
To conclude, you can now easily add text and image watermarks to your presentation slides using Java. Furthermore, you learned to apply watermarks to all the slides as well as to some specific slides of the presentation.