本文将详细介绍如何使用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);
}
}
效果图: