Add / remove watermark to Java PowerPoint

Watermarks are characters, logos, and figures that display copyright to prevent theft of still images and videos. This time, I will show you how to add/remove image watermarks and text watermarks to PowerPoint in Java using Spire.Presentation for Java.

Preparation

1. From the official website of E-iceblue Free Spire. Presentation for Java Download the free version.

f:id:lendoris:20210106113230p:plain

2. Launch the IDE to create a new project, then add the appropriate Spire. Presentation.jar to the reference that was in the installed file.

 f:id:lendoris:20210106113242p:plain

Original file

f:id:lendoris:20210106113408p:plain

Character Watermark

```java import com.spire.presentation.*; import com.spire.presentation.drawing.FillFormatType; import java.awt.*; import java.awt.geom.Rectangle2D;

public class watermark { public static void main(String[] args) throws Exception {

    //Create a presentation object.
    Presentation presentation = new Presentation();
    presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");

    //Sets the width and length of the watermark.
    int width= 400;
    int height= 300;

    //Create a rectangular field.
    Rectangle2D.Double rect = new Rectangle2D.Double((presentation.getSlideSize().getSize().getWidth() - width) / 2,
            (presentation.getSlideSize().getSize().getHeight() - height) / 2, width, height);

    //Add a shape to the rectangular field.
    IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, rect);

    /Place the shape design.
    shape.getFill().setFillType(FillFormatType.NONE);
    shape.getShapeStyle().getLineColor().setColor(Color.white);
    shape.setRotation(-45);
    shape.getLocking().setSelectionProtection(true);
    shape.getLine().setFillType(FillFormatType.NONE);

    //Add text to shape.
    shape.getTextFrame().setText("Copying prohibited");
    PortionEx textRange = shape.getTextFrame().getTextRange();

    //Place the watermark design.
    textRange.getFill().setFillType(FillFormatType.SOLID);
    textRange.getFill().getSolidColor().setColor(Color.pink);
    textRange.setFontHeight(50);

    //you save.
    presentation.saveToFile("output/result.pptx", FileFormat.PPTX_2010);
}

}


 <h4> <strong> Completion example </strong> </h4>
<p><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/l/lendoris/20210106/20210106113430.png " alt="f:id:lendoris:20210106113430p:plain" title="" class="hatena-fotolife" itemprop="image" /></p>
 <h4> <strong> Image watermark </strong> </h4>

```java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.io.File;


public class addImageWatermark {

    public static void main(String[] args) throws Exception {
        //Load the document.
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //Get the image watermark.

        File file =new File("logo.png ");
        IImageData image = presentation.getImages().append(ImageIO.read(file));

        //Gets the background attributes of the slide and places the image fill.
 presentation.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM);
        presentation.getSlides().get(0).getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
        presentation.getSlides().get(0).getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
        presentation.getSlides().get(0).getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(image);

        
        //you save
        presentation.saveToFile("addImageWatermark.pptx";, FileFormat.PPTX_2013);
    }
}

Completion example

f:id:lendoris:20210106113546p:plain

Code to remove watermark

import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

public class removeTextOrImageWatermark {

    public static void main(String[] args) throws Exception {
        //Load the document.
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //Remove the watermark in the textbook.
        for (int i = 0; i < presentation.getSlides().getCount(); i++)
        {
            for (int j = 0; j < presentation.getSlides().get(i).getShapes().getCount(); j++)
            {
                if (presentation.getSlides().get(i).getShapes().get(j) instanceof IAutoShape)
                {
                    IAutoShape shape = (IAutoShape)presentation.getSlides().get(i).getShapes().get(j);
                    if (shape.getTextFrame().getText().contains("E-iceblue"))
                    {
                        presentation.getSlides().get(i).getShapes().remove(shape);
                    }
                }
            }
        }

        //Remove the watermark in the image.
        for (int i = 0; i < presentation.getSlides().getCount(); i++)
        {
            presentation.getSlides().get(i).getSlideBackground().getFill().setFillType(FillFormatType.NONE);
        }

        //you save.
        presentation.saveToFile("removeTextOrImageWatermark.pptx";, FileFormat.PPTX_2013);
    }
}

 

 

Recommended Posts

Add / remove watermark to Java PowerPoint
Add multi-letter watermark to Java Word
Add watermark to Java to PDF document
Convert Java Powerpoint to XPS
Java (add2)
Java (add)
Java (remove)
[Java] Add WordArt to Word document
[Java] How to add data to List (add, addAll)
Add Document to Azure Search Service (Java)
Add footnotes to Word documents in Java
Add SameSite attribute to cookie in Java
Introduction to java
[Java] Add quotes only to specific CSV columns
Java adds a text box to PowerPoint slides
[Java] Article to add validation with Spring Boot 2.3.1.
Desktop: OpenCV Add WaterMark
Add files to jar files
Changes from Java 8 to Java 11
Sum from Java_1 to 100
[Java] Connect to MySQL
Use Maven to add your favorite Java library to your environment.
Kotlin's improvements to Java
[Java] Initialize, add, get
From Java to Ruby !!
[Java] [XML signature] Add prefix and ID to Signature tag
java: Add date [Note]
[Java] How to use Map
How to lower java version
Migration from Cobol to JAVA
[Java] How to use Map
Java adds table to PDF
How to uninstall Java 8 (Mac)
Java to play with Function
Java --How to make JTable
How to add ActionText function
How to use java Optional
How to minimize Java images
Create hyperlinks in Java PowerPoint
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] Introduction to lambda expressions
4 Add println to the interpreter
[Java] How to use string.format
Shell to kill Java process
Insert footer in Java Powerpoint
How to set Java constants
Connect to DB with Java
Connect to MySQL 8 with Java
[java] Reasons to use static
[Rails] Add column to devise
How to use Java variables
[Java] Introduction to Stream API
How to convert Java radix
[Java] Convert ArrayList to array
Java thread to understand loosely
[Java] How to implement multithreading
[Java] How to use Optional ①
From Ineffective Java to Effective Java