首页 生活 百科 科技 职场 学习 宠物
当前位置: 首页 > 生活 >

ppt如何添加水印效果

53次浏览     发布时间:2023-12-11 19:56:09    

在PPT幻灯片中,可通过添加形状的方式,来实现类似水印的效果,可添加单一文本水印效果,即幻灯片中只有一个文本水印;也可以添加多行(平铺)文本水印效果,即幻灯片中以一定方式平铺排列多个文本水印效果。本文主要以C#程序代码为例介绍第二种水印添加方法。

程序环境

  • 需引入以下程序集文件,如图:

其中,Spire.Presentation.dll程序集,需下载安装至本地(也可以通过Nuget下载),这里使用的免费版

  • .NET Framework 4.8

详细代码

【C#】

using Spire.Presentation;using Spire.Presentation.Drawing;using System;using System.Drawing;using System.Windows.Forms;namespace TextWatermark2{    class Program    {        static void Main(string[] args)        {            //加载PPT文档            Presentation ppt = new Presentation();            ppt.LoadFromFile("test.pptx");            //获取需要添加的水印的幻灯片(第一张幻灯片)            ISlide slide = ppt.Slides[0];            //创建水印文本            Font font = new Font("宋体", 20);            String watermarkText = "内部资料";            SizeF size = TextRenderer.MeasureText(watermarkText, font);            //指定水印添加的起始坐标位置            float x = 50;            float y = 80;            for (int i = 0; i < 4; i++)            {                for (int j = 0; j < 4; j++)                {                    //绘制文本,设置文本格式                    RectangleF rect = new RectangleF(x, y, size.Width, size.Height);                    IAutoShape shape = slide.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 = watermarkText;                    TextRange textRange = shape.TextFrame.TextRange;                    textRange.Fill.FillType = FillFormatType.Solid;                    textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink);                    textRange.EastAsianFont = new TextFont(font.Name);                    textRange.FontHeight = font.Size;                    x += (100 + size.Width);                }                x = 30;                y += (100 + size.Height);            }            //保存文档            ppt.SaveToFile("TextWatermark.pptx", FileFormat.Pptx2013);            System.Diagnostics.Process.Start("TextWatermark.pptx");        }    }}

完成代码后,执行程序,生成结果文档。在结果文档中可查看水印添加效果,如下图:

为什么下雨房子漏水(暴雨导致的房屋漏水或许无须自己花钱维修)

檀木分为什么(檀木之汇集)

树脂为什么会粘(乙烯基树脂固化后表面发黏的原因是什么?)

石斛为什么煮出紫色(怎样在1分钟内的泡好一杯石斛茶?)

工程瓷砖为什么便宜(我装修的时候买了工程砖,很后悔)

为什么分辨石英(水晶-石英结构与形成)