loading...

How to add image and text watermark to presentation slides

eiceblue profile image E-iceblue Product Family ・2 min read

There are different concepts for what Watermark is, but usually when we need to add watermark to our documents is either to discourage others from unauthorized copying or to add a background to the document to display the company logo. This section will show you how to add text watermark and image watermark in PowerPoint document in Java applications.

Add Image Watermark
Image watermakr are used to make the presentation slides more attractive and shows the copyright information of the presentation slides. The image watermark on the presentation slides actually is the image background to make it looks like watermark.

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.SlideBackground;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;


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

        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //presentation.getSlides().get(0).getSlideBackground().getType()= presentation.;
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream("ima.png"));
        IImageData imageData = presentation.getImages().append(bufferedImage);

        //apply the image to the specific slide as background
        SlideBackground background = presentation.getSlides().get(1).getSlideBackground();
        background.setType(BackgroundType.CUSTOM);
        background.getFill().setFillType(FillFormatType.PICTURE);
        background.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
        background.getFill().getPictureFill().getPicture().setEmbedImage(imageData);

        //save the file
        presentation.saveToFile("output/ImageWatermark.pptx", FileFormat.PPTX_2013);
        presentation.dispose();
    }
}

Output of image watermark on the presentation slide:

Image watermark

Add Text Watermark

The text watermark is based on shape, and it uses the locking property of shape to protect the shape from edited or copied.

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

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

        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //Set the width and height of watermark string
        int width= 400;
        int height= 300;
        //Define a rectangle range
        Rectangle2D.Double rect = new Rectangle2D.Double((presentation.getSlideSize().getSize().getWidth() - width) / 2,
                (presentation.getSlideSize().getSize().getHeight() - height) / 2, width, height);

        //Add a rectangle shape with a defined range
        IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, rect);

        //Set the style of shape
        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("E-iceblue");
        PortionEx textRange = shape.getTextFrame().getTextRange();

        //Set the style of the text range
        textRange.getFill().setFillType(FillFormatType.SOLID);
        textRange.getFill().getSolidColor().setColor(Color.pink);
        textRange.setFontHeight(50);

        //Save the document
        presentation.saveToFile("output/TextWatermark.pptx", FileFormat.PPTX_2010);
    }
}

Output of text watermark on the presentation slide:
Text watermark

Posted on by:

Discussion

pic
Editor guide