C# 处理PPT水印(三)—— 在PPT中添加多行(平铺)文本水印效果
在PPT幻灯片中,可通过添加形状的方式,来实现类似水印的效果,可添加单一文本水印效果,即幻灯片中只有一个文本水印;也可以添加多行(平铺)文本水印效果,即幻灯片中以一定方式平铺排列多个文本水印效果。本文主要以C#程序代码为例介绍第二种水印添加方法,另附VB.NET代码供参考。
程序环境
- 需引入以下程序集文件,如图:

其中,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");
}
}
}
【VB.NET】
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing
Imports System.Windows.Forms Namespace TextWatermark2
Class Program
Private Shared Sub Main(args As String())
'加载PPT文档
Dim ppt As New Presentation()
ppt.LoadFromFile("test.pptx") '获取需要添加的水印的幻灯片(第一张幻灯片)
Dim slide As ISlide = ppt.Slides(0) '创建水印文本
Dim font As New Font("宋体", 20)
Dim watermarkText As [String] = "内部资料"
Dim size As SizeF = TextRenderer.MeasureText(watermarkText, font) '指定水印添加的起始坐标位置
Dim x As Single = 50
Dim y As Single = 80
For i As Integer = 0 To 3
For j As Integer = 0 To 3
'绘制文本,设置文本格式
Dim rect As New RectangleF(x, y, size.Width, size.Height)
Dim shape As IAutoShape = 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
Dim textRange As 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)
Next
x = 30
y += (100 + size.Height)
Next '保存文档
ppt.SaveToFile("TextWatermark.pptx", FileFormat.Pptx2013)
System.Diagnostics.Process.Start("TextWatermark.pptx")
End Sub
End Class
End Namespace
完成代码后,执行程序,生成结果文档。在结果文档中可查看水印添加效果,如下图:

其他关于C#操作PPT水印的方法可参考以下相关文章:
- 添加单一水印效果:C# 添加文本和图片水印到PPT
- 删除水印效果:C# 删除PPT中的水印
(本文完)
转载请注明出处!
C# 处理PPT水印(三)—— 在PPT中添加多行(平铺)文本水印效果的更多相关文章
- Java 在Word中添加多行图片水印
Word中设置水印效果时,不论是文本水印或者是图片水印都只能添加单个文字或者图片到Word页面,效果比较单一,本文通过Java代码示例介绍如何在页面中添加多行图片水印效果,即水印效果以多个图片平铺到页 ...
- C# 往Datatable中添加新行的步骤
以一个实例说明 //录入年份绑定 public void YearList(FineUIPro.DropDownList ddlYear) { //年份从15年到当前年//起止年份 ; int yea ...
- LODOP中设置设置图片平铺水印,超文本透明
之前的博文:LODOP中平铺图片 文本项Repeat. 该博文中是平铺的图片,上面是文本.如果是图片add_print_image和add_print_text纯文本,这两个打印项设计的,可以直接通过 ...
- Android中设定背景图片平铺。
注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 在做Android开发时,我们常常需要为程序设定一个背景,但由于现在的Android设备尺寸不一,如果随便设置一个图片为背景,那么很 ...
- android中可以使用bitmap的平铺,镜像平铺等减小图片带来的apk过大的问题
bitmap的平铺.镜像drawable文件夹中新建bitmap,其中的tileMode属性 tileMode 属性就是用于定义背景的显示模式: disabled 默认值,表示不使用平铺 cla ...
- ajax异步获取数据后动态向表格中添加数据(行)
因为某些原因,项目中突然需要做自己做个ajax异步获取数据后动态向表格中添加数据的页面,网上找了半天都没有 看到现成的,决定自己写个例子 1.HTML页面 <!doctype html> ...
- CUBRID学习笔记 36 在net中添加多行记录
using System.Data.Common; using CUBRID.Data.CUBRIDClient; namespace Sample { class Add_MultipleRows ...
- excel中添加拼接行
Sub 万途标签()Dim iFor i = 1 To Sheets.Count If Sheets(i).Name = "数据表" Then If MsgBo ...
- 宏开发:excel中添加拼接行
Sub 万途标签()Dim iFor i = 1 To Sheets.Count If Sheets(i).Name = "数据表" Then If MsgBo ...
随机推荐
- Notepad++ 替换 CRLF 为 LF
对于文件中每一行的结尾符号,Windows 下默认为 CRLF,而 Unix 下默认为 LF. 所以经常会有这样的情况发生:在 Windows 系统下编辑的文件放在 Unix 下不能正常执行,比如 b ...
- Codeforces Round #627 (Div. 3) D - Pair of Topics(双指针)
题意: 有长为n的a,b两序列,问满足ai+aj>bi+bj(i<j)的i,j对数. 思路: 移项得:(ai-bi)+(aj-bj)>0,i<j即i!=j,用c序列保存所有ai ...
- bzoj1500: [NOI2005]维修数列 (Splay+变态题)
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 11353 Solved: 3553 [Submit][Status][Discuss] Descrip ...
- zjnu1709 UZASTOPNI (bitset,树形dp)
Description Petar is throwing a birthday party and he decided to invite some of the employees of his ...
- Educational Codeforces Round 94 (Rated for Div. 2) D. Zigzags (枚举,前缀和)
题意:有一长度为\(n(4\le n\le 3000)\)的数组,选择四个位置\((i,j,k,l)\ (1\le i<j<k\le n)\),使得\(a_i=a_k\)并且\(a_j=a ...
- POJ 3281 Dining(最大流板子)
牛是很挑食的.每头牛都偏爱特定的食物和饮料,其他的就不吃了. 农夫约翰为他的牛做了美味的饭菜,但他忘了根据它们的喜好检查菜单.虽然他不可能喂饱所有的人,但他想让尽可能多的奶牛吃上一顿有食物和水的大餐. ...
- hdu3516 Tree Construction
Problem Description Consider a two-dimensional space with a set of points (xi, yi) that satisfy xi & ...
- 【转】K8S中部署Helm
K8S中的包管理工具 1. 客户端Helm(即Helm) 通过脚本安装:curl https://raw.githubusercontent.com/helm/helm/master/scripts ...
- codeforces 01B
B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard inp ...
- 『数据结构与算法』二叉查找树(BST)
微信搜索:码农StayUp 主页地址:https://gozhuyinglong.github.io 源码分享:https://github.com/gozhuyinglong/blog-demos ...