之前介绍过如何给PPT添加图片和文本水印, 本文将详细介绍如何使用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")
效果展示: