C#-添加、删除课件水印(文本、图片水印).docx
文本预览下载声明
C# 添加、删除PPT水印【引言】水印是一种有效的文档防伪手段,在现代办公中非常实用。在接下来的示例中,将介绍如何通过C#编程语言来实现Power Point幻灯片添加水印。我们知道,水印可以分为文本水印、图片水印,在此也将分别介绍实现两种水印效果的具体方法。另外,水印幻灯片中已经存在的水印,如果我们想要去除水印效果,也可以下面介绍的关于删除水印的方法。【工具】Free Spire.Presentation for .NET 3.3 (社区版)【示例1】添加文本水印C#using System;using System.Text;using Spire.Presentation;using System.Drawing;using Spire.Presentation.Drawing;using System.Windows.Forms;namespace InsertWatermark_PPT{ class Program { static void Main(string[] args) { //初始化一个Presentation类实例并加载文档 Presentation ppt = new Presentation(); ppt.LoadFromFile(test.pptx, FileFormat.Pptx2010); //初始化一个Font类字体实例并实例化字体格式 Font stringFont = new Font(Arial, 90); Size size = TextRenderer.MeasureText(内部资料, stringFont); //绘制一个Shape并指定大小、填充颜色、边框颜色和旋转度 RectangleF rect = new RectangleF((ppt.SlideSize.Size.Width - size.Width) / 2, (ppt.SlideSize.Size.Height - size.Height) / 2, size.Width, size.Height); IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect); shape.Fill.FillType = FillFormatType.None; shape.ShapeStyle.LineColor.Color = Color.White; shape.Rotation = -45; //设定形状保护属性、填充模式 shape.Locking.SelectionProtection = true; shape.Line.FillType = FillFormatType.None; //设置文本水印文字,并设置水印填充模式、水印颜色、大小等 shape.TextFrame.Text = 内部资料; TextRange textRange = shape.TextFrame.TextRange; textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid; textRange.Fill.SolidColor.Color = Color.FromArgb(150, Color.LightBlue); textRange.FontHeight = 90; //保存并打开文档 ppt.SaveToFile(TextWatermark.pptx, FileFormat.Pptx2010); System.Diagnostics.Process.Start(TextWatermark.pptx); } }}文本水印添加效果:【示例2】添加图片水印C#using System;using System.Drawing;using Spire.Presentation;using Spire.Presentation.Drawing;namespace ImageWatermark_PPT{ class Program { static void Main(string[] args) { //初始化一个Presentation类实例并加载文档 Presentation ppt = new Presentation(); ppt.LoadFromFile(test.pptx, FileFormat.Pptx2010); //为第一张幻灯片设置背景图片类型和样式 ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.Backgroun
显示全部