每个powerpoint演示文稿都有一个幻灯片母版,它包含幻灯片的所有样式。通过选择幻灯片母版,然后采用主题,添加背景图片或更改配色方案,可以快速改变整个演示文稿的外观。
在本文中,您将学习如何获取和修改现有演示文稿中的幻灯片母版。
测试文档:
c#
//加载pdf文档
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//获取文档中的母版
imasterslide masterslide = ppt.masters[0];
//在母版上添加背景图片
string backgroundpic = "background.png";
rectanglef rect = new rectanglef(0, 0, ppt.slidesize.size.width, ppt.slidesize.size.height);
masterslide.slidebackground.fill.filltype = fillformattype.picture;
iembedimage image = masterslide.shapes.appendembedimage(shapetype.rectangle, backgroundpic, rect);
masterslide.slidebackground.fill.picturefill.picture.embedimage = image as iimagedata;
//更改母版主题颜色
masterslide.theme.colorscheme.accent1.color = color.red;
masterslide.theme.colorscheme.accent2.color = color.rosybrown;
masterslide.theme.colorscheme.accent3.color = color.ivory;
masterslide.theme.colorscheme.accent4.color = color.lavender;
masterslide.theme.colorscheme.accent5.color = color.black;
//在母版上添加图片
string logo = "logo.png";
iembedimage imageshape = masterslide.shapes.appendembedimage(shapetype.rectangle, logo, new rectanglef(40, 40, 240, 65));
imageshape.line.fillformat.filltype = fillformattype.none;
//保存文档
ppt.savetofile("result.pptx", fileformat.pptx2013);
vb.net
'加载pdf文档
dim ppt as new presentation()
ppt.loadfromfile("sample.pptx")
'获取文档中的母版
dim masterslide as imasterslide = ppt.masters(0)
'在母版上添加背景图片
dim backgroundpic as string = "background.png"
dim rect as new rectanglef(0, 0, ppt.slidesize.size.width, ppt.slidesize.size.height)
masterslide.slidebackground.fill.filltype = fillformattype.picture
dim image as iembedimage = masterslide.shapes.appendembedimage(shapetype.rectangle, backgroundpic, rect)
masterslide.slidebackground.fill.picturefill.picture.embedimage = trycast(image, iimagedata)
'更改母版主题颜色
masterslide.theme.colorscheme.accent1.color = color.red
masterslide.theme.colorscheme.accent2.color = color.rosybrown
masterslide.theme.colorscheme.accent3.color = color.ivory
masterslide.theme.colorscheme.accent4.color = color.lavender
masterslide.theme.colorscheme.accent5.color = color.black
'在母版上添加图片
dim logo as string = "logo.png"
dim imageshape as iembedimage = masterslide.shapes.appendembedimage(shapetype.rectangle, logo, new rectanglef(40, 40, 240, 65))
imageshape.line.fillformat.filltype = fillformattype.none
'保存文档
ppt.savetofile("result.pptx", fileformat.pptx2013)
结果文档: