本文将详细介绍如何使用Spire.Presentation for Java给PPT文档添加图片水印。
示例文档:
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 {
//加载示例文档
Presentation presentation = new Presentation();
presentation.loadFromFile("Sample.pptx");
//获取水印图片
File file =new File("logo.png");
IImageData image = presentation.getImages().append(ImageIO.read(file));
//获取幻灯片背景属性,设置图片填充
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);
//保存文档
presentation.saveToFile("addImageWatermark.pptx";, FileFormat.PPTX_2013);
}
}
效果图: