C# 处理PPT水印(一)——添加水印效果(文字水印、图片水印)
对文档添加水印可以有效声明和保护文档,是保护重要文件的方式之一。在PPT文档中同样也可以设置水印,包括文本水印和图片水印,本文将讲述如何通过Spire.Presentation for .NET来对PPT添加水印,下载安装Free Spire.Presentationfor .NET后,添加引用dll文件,参考下面的操作步骤,完成水印添加。
1.添加文本水印
步骤一:初始化Presentation类实例,并加载文档
Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);
步骤二:初始化一个Font类实例,并实例化字体格式
Font stringFont = new Font("Arial", );
Size size = TextRenderer.MeasureText("内部资料", stringFont);
步骤三:绘制一个shape并指定大小、填充颜色、边框颜色和旋转角度
RectangleF rect = new RectangleF((ppt.SlideSize.Size.Width - size.Width) / , (ppt.SlideSize.Size.Height - size.Height) / , size.Width, size.Height);
IAutoShape shape = ppt.Slides[].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect);
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;
shape.Rotation = -;
步骤四:设定形状属性为保护属性
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(, Color.Gray);
textRange.FontHeight = ;
步骤六:保存文档
ppt.SaveToFile("TextWatermark.pptx", FileFormat.Pptx2010);
完成以上代码步骤后,调试运行项目程序,生成文件(可在该项目文件中bin>Debug中查看),如下图所示:

全部代码:
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", );
Size size = TextRenderer.MeasureText("内部资料", stringFont); //绘制一个Shape并指定大小、填充颜色、边框颜色和旋转度
RectangleF rect = new RectangleF((ppt.SlideSize.Size.Width - size.Width) / , (ppt.SlideSize.Size.Height - size.Height) / , size.Width, size.Height);
IAutoShape shape = ppt.Slides[].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect);
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;
shape.Rotation = -; //设定形状属性为保护属性
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(, Color.LightBlue);
textRange.FontHeight = ; //保存文档
ppt.SaveToFile("TextWatermark.pptx", FileFormat.Pptx2010);
}
}
View full Code
2.添加图片水印
步骤一:初始化一个Presentation类实例并加载文档
Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);
步骤二: 为第一张幻灯片设置背景图片类型和样式
ppt.Slides[].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[].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[].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
步骤四:保存文档
ppt.SaveToFile("ImageWatermark1.pptx", FileFormat.Pptx2010);

全部代码:
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[].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[].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[].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image; //保存文档
ppt.SaveToFile("ImageWatermark1.pptx", FileFormat.Pptx2010);
}
}
}
View full Code
以上是对PPT添加水印的代码操作,希望该方法能提供帮助,感谢阅读!
C# 处理PPT水印(一)——添加水印效果(文字水印、图片水印)的更多相关文章
- ASP.NET(C#)图片加文字、图片水印,神啊,看看吧
ASP.NET(C#)图片加文字.图片水印 一.图片上加文字: //using System.Drawing; //using System.IO; //using System.Drawing.Im ...
- 开发笔记:PDF生成文字和图片水印
背景 团队手里在做的一个项目,其中一个小功能是用户需要上传PDF文件到文件服务器上,都是一些合同或者技术评估文档,鉴于知识版权和防伪的目的,需要在上传的PDF文件打上水印, 这时候我们需要提供能力给客 ...
- PHP 文字,图片水印,缩略图,裁切成小图(大小变小)
文字水印基本思路:1.用getimagesize()获取图片的信息(as:大小,属性等):2.根据图片信息用imagecreatefromjpeg ()/imagecreatefromgif/imag ...
- PHP加水印代码 支持文字和图片水印
PHP加图片水印.文字水印类代码,PHP加水印类,支持文字图片水印的透明度设置.水印图片背景透明.自己写的一个类,因为自己开发的一套CMS中要用到,网上的总感觉用着不顺手,希望大家也喜欢这个类,后附有 ...
- C# 给图片添加透明的文字、图片水印
#region 添加水印 /// <summary> /// 添加文字水印 /// </summary> /// <param name="image" ...
- vue中添加文字或图片水印
首先引用warterMark.js,内容如下 'use strict' var watermark = (className,str,type) => { let dom = document. ...
- CSS3动画实现高亮光弧效果,文字和图片(一闪而过)
前言 好久没有写博客啦,高亮文字和图片一闪而过的特效,用CSS3来写 先看文字吧, 就上代码了 .shadow { /* 背景颜色线性渐变 */ /* 老式写法 */ /* linear为线性渐变,也 ...
- Android给图片加文字和图片水印
我们在做项目的时候有时候需要给图片添加水印,水寒今天就遇到了这样的问题,所以搞了一个工具类,贴出来大家直接调用就行. /** * 图片工具类 * @author 水寒 * 欢迎访问水寒的个人博客:ht ...
- php文字、图片水印功能函数封装
一直在做有关php文字图片上传方面的工作,所以把此功能函数整理了一次,现在分享给大家. <?php class image { var $g_img; var $g_w; var $g_h; v ...
- IOS 绘制基本图形(画文字、图片水印)
- (void)drawRect:(CGRect)rect { // Drawing code // [self test]; // 1.加载图片到内存中 UIImage *image = [UIIm ...
随机推荐
- C#转发Post请求,包括参数和文件
/// <summary> /// 转发Post请求 /// </summary> /// <param name="curRequest">要 ...
- vue-router下的html5 history在iis服务器上的设置 vue去掉#
转自:https://www.cnblogs.com/zzsdream/p/6576639.html 1.安装 url rewrite模块到IIS 下载地址 2.在web.config文件中 syst ...
- k8s probe
livenessProbe: httpGet: path: /abc/401 port: 8384 scheme: HTTP
- Ubuntu环境下配置darknet
本教程基于Linux物理机进行相关配置,要求物理机中包含N卡且Capbility>=3.0,小于3.0(Fermi架构)只允许配置cuda,不能配置使用Cudnn: 本教程分为: 1.安装NVI ...
- 权限系统设计-day01
数据库表的设计: 关键流程思考: 权限在SSH系统中应该表现为什么东西? 小胖这个用户登陆:1,检查用户名和密码;2,检查通过; 1),得到小胖这个用户的对应的所有的角色:R1 2),根据所有的角 ...
- C语言面试题分类->排序算法
1.选择排序. 每次将最小的数,与剩余数做比较.找到更小的,做交换. 时间复杂度:O(n²) 空间复杂度:O(1) 优缺点:耗时但内存空间使用小. void selectSort(int *p,int ...
- Asp.Net Core中使用Swagger,你不得不踩的坑
很久不来写blog了,换了新工作后很累,很忙.每天常态化加班到21点,偶尔还会到凌晨,加班很累,但这段时间,也确实学到了不少知识,今天这篇文章和大家分享一下:Asp.Net Core中使用Swagge ...
- [Swift]LeetCode397. 整数替换 | Integer Replacement
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...
- HoloLens开发手记- SpectatorView for iOS编译指南
微软前两天发布了HoloLens 2,给MR开发带来了新的希望,全面的性能和显示效果提升,让人期待. 去年推出的预览版的全新SpectatorView for iOS解决方案,这允许我们直接使用带AR ...
- 【Spark篇】---Spark中Master-HA和historyServer的搭建和应用
一.前述 本节讲述Spark Master的HA的搭建,为的是防止单点故障. Spark-UI 的使用介绍,可以更好的监控Spark应用程序的执行. 二.具体细节 1.Master HA 1.Mast ...