在幻灯片中,所有元素都以shape 形式添加到powerpoint文档中。我们前面介绍了如何使用spire.presentation,该文将详细介绍如何使用spire.presentation读取幻灯片中文本框的位置大小,以及文本字体大小,字体类型和是否为粗体,斜体,是否设置下划线等。除了能获取图片,spire.presentation 还支持获取幻灯片中图片的位置、大小等信息。
c#
//初始化一个presentation对象对加载文档
presentation presentation = new presentation();
presentation.loadfromfile("test.ppt");
//获取第一个shape
iautoshape shape = presentation.slides[0].shapes[0] as iautoshape;
//获取位置
float left = shape.left;
float top = shape.top;
//获取大小
float width = shape.width;
float height = shape.height;
//获取文本框里的段落
textparagraph par = shape.textframe.paragraphs[0];
//获取段落里文本的字体
textfont font = par.textranges[0].eastasianfont;
string name = font.fontname;
//加粗
tristate boldstate = par.textranges[0].isbold;
//字体大小
float size = par.textranges[0].fontheight;
//斜体
tristate italicstate = par.textranges[0].isitalic;
//下划线
textunderlinetype underline = par.textranges[0].textunderlinetype;
//获取第二個shape(图片)
slidepicture picture = presentation.slides[0].shapes[1] as slidepicture;
//图片位置
float pleft = picture.left;
float ptop = picture.top;
//图片大小
float pwidth = picture.width;
float pheight = picture.height;
//获取图片
pictureshape pic = picture.picturefill.picture;
image image = pic.embedimage.image;
//保存图片
image.save("picture.jpg");
vb.net
'初始化一个presentation对象对加载文档
dim presentation as new presentation()
presentation.loadfromfile("test.ppt")
'获取第一个shape
dim shape as iautoshape = trycast(presentation.slides(0).shapes(0), iautoshape)
'获取位置
dim left as single = shape.left
dim top as single = shape.top
'获取大小
dim width as single = shape.width
dim height as single = shape.height
'获取文本框里的段落
dim par as textparagraph = shape.textframe.paragraphs(0)
'获取段落里文本的字体
dim font as textfont = par.textranges(0).eastasianfont
dim name as string = font.fontname
'加粗
dim boldstate as tristate = par.textranges(0).isbold
'字体大小
dim size as single = par.textranges(0).fontheight
'斜体
dim italicstate as tristate = par.textranges(0).isitalic
'下划线
dim underline as textunderlinetype = par.textranges(0).textunderlinetype
'获取第二個shape(图片)
dim picture as slidepicture = trycast(presentation.slides(0).shapes(1), slidepicture)
'图片位置
dim pleft as single = picture.left
dim ptop as single = picture.top
'图片大小
dim pwidth as single = picture.width
dim pheight as single = picture.height
'获取图片
dim pic as pictureshape = picture.picturefill.picture
dim image as image = pic.embedimage.image
'保存图片
image.save("picture.jpg")