C#C# 怎么着添加水印到PPT

一体代码:

shape.TextFrame.Text = "内部资料";
TextRange textRange = shape.TextFrame.TextRange;
textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.Gray);
textRange.FontHeight = 45;

1.添加文本水印

 C# 1

手续二: 为第一张幻灯片设置背景图片类型和体制

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

C# 2C# 3

步骤一:起初化一个Presentation类实例并加载文档

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(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

            //为第一张幻灯片设置背景图片类型和样式
            ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
            ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
            ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;

            //加载图片并为第一张幻灯片设置水印效果
            Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\images\1.jpg");
            IImageData image = ppt.Images.Append(img);
            ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

            //保存文档
            ppt.SaveToFile("ImageWatermark1.pptx", FileFormat.Pptx2010);
        }
    }
}
ppt.SaveToFile("TextWatermark.pptx", FileFormat.Pptx2010);

C# 4

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(@"C:\Users\Administrator\Desktop\sample.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);
        }
    }

View full Code

步骤三:绘制一个shape并指定大小、填充颜色、边框颜色和旋转角度

手续六:保存文档

步骤四:设定形状属性为保养属性

2.添加图形水印

 

整整代码:

Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\images\1.jpg");
IImageData image = ppt.Images.Append(img);
ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;

步骤三:加载图片并为第一张幻灯片设置水印

C# 5C# 6

步骤五:设置文本大小、颜色

Font stringFont = new Font("Arial", 90);
Size size = TextRenderer.MeasureText("内部资料", stringFont);

对文档添加水印可以使得表明和保安文档,是维护重要文件的法门之一。在PPT文档中一致也得以安装水印,包括文件水印和图表水印,本文将讲述怎样通过Spire.Presentation
for .NET来对PPT添加水印,下载安装Free Spire.Presentationfor
.NET
后,添加引用dll文件,参考下边的操作步骤,完成水印添加。

手续一:开首化Presentation类实例,并加载文档

步骤四:保存文档

 

shape.Locking.SelectionProtection = true;
shape.Line.FillType = FillFormatType.None;

 

View full Code

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;
Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);
 ppt.SaveToFile("ImageWatermark1.pptx", FileFormat.Pptx2010);

上述是对PPT添加水印的代码操作,希望该格局能提供襄助,感谢阅读!

形成以上代码步骤后,调试运行品种先后,生成文书(可在该项目文件中bin>Debug中查阅),如下图所示:

步骤二:最先化一个Font类实例,并实例化字体格式

相关文章