本文介绍使用spire.presentation for java删除ppt幻灯片中的图片。
import com.spire.presentation.*;
public class removeimages {
public static void main(string[] args) throws exception{
//加载ppt文档
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//获取指定幻灯片
islide slide = ppt.getslides().get(1);
//遍历幻灯片中的形状
for( int i = 0; i< slide.getshapes().getcount();i ){
ishape shape = slide.getshapes().get(i);
//删除图片
if(shape instanceof slidepicture){
slidepicture pic = (slidepicture) shape;
slide.getshapes().remove(pic);
}
}
//保存文档
ppt.savetofile("removeimgs.pptx", fileformat.pptx_2013);
ppt.dispose();
}
}
图片删除效果: