本文介绍如何使用Spire.Presentation for Java在PowerPoint文档中插入一张图片并为图片设置超链接。
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.geom.Rectangle2D;
public class AddHyperlinkToImage {
public static void main(String[] args) throws Exception {
//创建Presentation对象
Presentation presentation = new Presentation();
//获取第一张幻灯片
ISlide slide = presentation.getSlides().get(0);
//添加图片到幻灯片
String imaPath = "C:\\Users\\Administrator\\Desktop\\logo.png";
Rectangle2D.Float rect = new Rectangle2D.Float(50, 50, 220, 60);
IEmbedImage image = slide.getShapes().appendEmbedImage(ShapeType.RECTANGLE, imaPath, rect);
//将图片形状的边线设置为无
image.getLine().setFillType(FillFormatType.NONE);
//添加超链接到图片
ClickHyperlink hyperlink = new ClickHyperlink("https://www.e-iceblue.com");
image.setClick(hyperlink);
//保存文档
presentation.saveToFile("output/ImageHyperLink.pptx", FileFormat.PPTX_2013);
}
}