本文將對C#處理PPT幻燈片中的水印進一步說明和介紹。在C# 處理PPT水印(一)一文中,分享瞭如何插入水印效果的方法,包括插入文字水印效果、插入圖片做爲水印效果兩種狀況,那對於不須要水印效果的狀況,要如何來去除PPT中已有的水印效果呢,具體實現步驟,可參考下面將要講述的方法。html
PS:安裝後,注意在編輯代碼時,添加引用Spire.Presentation.dll(dll文件可在安裝路徑下的Bin文件夾中獲取)ide
測試文件中的文字水印效果以下:工具
步驟1 :實例化Presentation類,加載含有水印效果的PPT文檔測試
Presentation ppt = new Presentation(); ppt.LoadFromFile("TextWatermark.pptx");
步驟2 :遍歷全部幻燈片,查找包含水印字樣的shape,並刪除spa
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); } } } }
步驟3:保存文檔並打開code
ppt.SaveToFile("RemoveTextWatermak.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("RemoveTextWatermak.pptx");
文字水印去除效果:orm
所有代碼:htm
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"); } } }
測試文件中的圖片水印效果以下:blog
步驟1 :實例化Presentation類,加載測試文檔圖片
Presentation ppt = new Presentation(); ppt.LoadFromFile("ImageWatermark.pptx");
步驟2 :遍歷每一張幻燈片, 設置背景填充類型爲None
for (int i = 0; i < ppt.Slides.Count; i++) { ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.None; }
步驟3 :保存文檔並打開
ppt.SaveToFile("RemovePicWatermak.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("RemovePicWatermak.pptx");
圖片水印去除效果:
所有代碼:
using Spire.Presentation; using Spire.Presentation.Drawing; namespace DeleteImageWatermark_PPT { class Program { static void Main(string[] args) { //實例化Presentation類,加載有圖片水印的PowerPoint文檔 Presentation ppt = new Presentation(); ppt.LoadFromFile("ImageWatermark.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"); } } }
以上是關於C# 去除PPT水印效果的方法介紹。
(本文完)
轉載請註明出處!