- using Spire.Presentation;
- namespace DeleteTextWatermark_PPT
- {
- class Program
- {
- static void Main(string[] args)
- {
- //实例化Presentation类,加载有水印的PowerPoint文档
- Presentation ppt = new Presentation();
- ppt.LoadFromFile("TextWatermark.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");
- }
- }
- }