本文介绍如何使用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);
}
}