之前介绍过, 本文将详细介绍如何使用spire.presentaion 来删除ppt文档中的图片水印和文本水印。
1.通过slidebackground.fill.filltype背景填充类型属性来删除图片水印
c#
//加载有图片水印的powerpoint文档
presentation ppt = new presentation();
ppt.loadfromfile(@"watermark.pptx");
//遍历每一张幻灯片, 设置背景填充类型为none
for (int i = 0; i < ppt.slides.count; i )
{
ppt.slides[0].slidebackground.fill.filltype = fillformattype.none;
}
//保存结果文档到本地并打开
ppt.savetofile("removepicwatermak.pptx", fileformat.pptx2010);
system.diagnostics.process.start("removepicwatermak.pptx");
vb.net
'加载有图片水印的powerpoint文档
dim ppt as new presentation()
ppt.loadfromfile("watermark.pptx")
'遍历每一张幻灯片, 设置背景填充类型为none
for i as integer = 0 to ppt.slides.count - 1
ppt.slides(0).slidebackground.fill.filltype = fillformattype.none
next
'保存结果文档到本地并打开
ppt.savetofile("removepicwatermak.pptx", fileformat.pptx2010)
system.diagnostics.process.start("removepicwatermak.pptx")
效果展示:
文本水印存在于一个shape里,确定了水印所在的这个形状然后删除它即可。
c#
//加载有水印的powerpoint文档
presentation ppt = new presentation();
ppt.loadfromfile(@"watermark.pptx");
//遍历每一张幻灯片, 查找水印文字内容所在的形状, 然后删除这个形状
for (int i = 0; i < ppt.slides.count; i )
{
for (int j = 0; j < ppt.slides[i].shapes.count; j )
{
if (ppt.slides[i].shapes[j] is iautoshape)
{
iautoshape shape = ppt.slides[i].shapes[j] as iautoshape;
if (shape.textframe.text.contains("内部资料"))
{
ppt.slides[i].shapes.remove(shape);
}
}
}
}
//保存结果文档到本地并打开
ppt.savetofile("removetextwatermak.pptx", fileformat.pptx2010);
system.diagnostics.process.start("removetextwatermak.pptx");
vb.net
'加载有水印的powerpoint文档
dim ppt as new presentation()
ppt.loadfromfile("watermark.pptx")
'遍历每一张幻灯片, 查找水印文字内容所在的形状, 然后删除这个形状
for i as integer = 0 to ppt.slides.count - 1
for j as integer = 0 to ppt.slides(i).shapes.count - 1
if typeof ppt.slides(i).shapes(j) is iautoshape then
dim shape as iautoshape = trycast(ppt.slides(i).shapes(j), iautoshape)
if shape.textframe.text.contains("内部资料") then
ppt.slides(i).shapes.remove(shape)
end if
end if
next
next
'保存结果文档到本地并打开
ppt.savetofile("removetextwatermak.pptx", fileformat.pptx2010)
system.diagnostics.process.start("removetextwatermak.pptx")
效果展示: