本文介绍使用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();
}
}
图片删除效果: