import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;public classCreateShapes_PPT {public static voidmain(String[] args) throws Exception {//创建PowerPoint文档
Presentation presentation = newPresentation();//添加一个三角形,并设置单色填充
IAutoShape shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.TRIANGLE, new Rectangle2D.Double(115, 130, 100, 100));
shape.getFill().setFillType(FillFormatType.SOLID);
shape.getFill().getSolidColor().setColor(Color.orange);
shape.getShapeStyle().getLineColor().setColor(Color.white);//添加一个椭圆,并设置图片填充
shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.ELLIPSE, new Rectangle2D.Double(290, 130, 150, 100));
shape.getFill().setFillType(FillFormatType.PICTURE);
shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
BufferedImage image= ImageIO.read(new File("logo.png"));
shape.getFill().getPictureFill().getPicture().setEmbedImage(presentation.getImages().append(image));
shape.getShapeStyle().getLineColor().setColor(Color.white);//添加一个心形,并设置图案填充
shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.HEART, new Rectangle2D.Double(515, 130, 130, 100));
shape.getFill().setFillType(FillFormatType.PATTERN);
shape.getFill().getPattern().setPatternType(PatternFillType.LARGE_GRID);
shape.getShapeStyle().getLineColor().setColor(Color.white);//添加一个五角星,并设置渐变填充
shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.FIVE_POINTED_STAR, new Rectangle2D.Double(115, 300, 115, 115));
shape.getFill().setFillType(FillFormatType.GRADIENT);
shape.getFill().getGradient().getGradientStops().append(0, KnownColors.RED);
shape.getFill().getGradient().getGradientStops().append(1, KnownColors.LIGHT_SALMON);
shape.getShapeStyle().getLineColor().setColor(Color.white);//添加一个矩形,并设置渐变填充
shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.HEXAGON, new Rectangle2D.Double(290, 300, 140, 125));
shape.getFill().setFillType(FillFormatType.GRADIENT);
shape.getFill().getGradient().getGradientStops().append(0, KnownColors.LIGHT_PINK);
shape.getFill().getGradient().getGradientStops().append(1, KnownColors.LIGHT_SKY_BLUE);
shape.getShapeStyle().getLineColor().setColor(Color.white);//添加一个向上的箭头,并设置渐变填充
shape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.DOUBLE_WAVE, new Rectangle2D.Double(515, 300, 130, 100));
shape.getFill().setFillType(FillFormatType.GRADIENT);
shape.getFill().getGradient().getGradientStops().append(1f, KnownColors.OLIVE);
shape.getFill().getGradient().getGradientStops().append(0, KnownColors.POWDER_BLUE);
shape.getShapeStyle().getLineColor().setColor(Color.white);//保存文档
presentation.saveToFile("AddShapes.pptx", FileFormat.PPTX_2010);
}
}