Watermark

Watermark (3)

This article will demonstrate how to use Spire.Presentaion for Java to remove text watermark and image watermark from the presentation slides.

Firstly, view the sample PowerPoint document with text and image watermark:

Java remove text or image watermark from presentation slides

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

public class removeTextOrImageWatermark {

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

        //Remove text watermark by removing the shape which contains the string "E-iceblue".
        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 image watermark
        for (int i = 0; i < presentation.getSlides().getCount(); i++)
        {
            presentation.getSlides().get(i).getSlideBackground().getFill().setFillType(FillFormatType.NONE);
        }

        //Save to file.
        presentation.saveToFile("removeTextOrImageWatermark.pptx";, FileFormat.PPTX_2013);
    }
}

Effective screenshot after removing text or image watermark:

Java remove text or image watermark from presentation slides

We have introduced how to use Spire.Presentaion for Java to add text watermark to PowerPoint document. This article will demonstrate how to add image watermark to presentation slides in java applications.

Firstly view the sample PowerPoint document:

Java insert image watermark to presentation slides

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 {
        //Create a PowerPoint document.
        Presentation presentation = new Presentation();

        //Load the file from disk.
        presentation.loadFromFile("Sample.pptx");

        //Get the image you want to add as image watermark.
        File file =new File("logo.png");
        IImageData image = presentation.getImages().append(ImageIO.read(file));

        //Set the properties of SlideBackground, and then fill the image as watermark.
        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);

        String result = "addImageWatermark.pptx";
        //Save to file.
        presentation.saveToFile(result, FileFormat.PPTX_2013);
    }
}

Effective screenshot after adding image watermark to PowerPoint document:

Java insert image watermark to presentation slides

Thursday, 13 December 2018 02:49

Java insert text watermark to presentation slides

Written by support iceblue

This article will demonstrate how to use Spire.Presentaion for Java to add text watermark to PowerPoint document.

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 PPT document and load the sample file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\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("Confidential");
        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/result.pptx", FileFormat.PPTX_2010);
    }

}

Java insert text watermark to presentation slides