在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水印(三)—— 在PPT中添加多行(平铺)文本水印效果的更多相关文章

  1. Java 在Word中添加多行图片水印

    Word中设置水印效果时,不论是文本水印或者是图片水印都只能添加单个文字或者图片到Word页面,效果比较单一,本文通过Java代码示例介绍如何在页面中添加多行图片水印效果,即水印效果以多个图片平铺到页 ...

  2. C# 往Datatable中添加新行的步骤

    以一个实例说明 //录入年份绑定 public void YearList(FineUIPro.DropDownList ddlYear) { //年份从15年到当前年//起止年份 ; int yea ...

  3. LODOP中设置设置图片平铺水印,超文本透明

    之前的博文:LODOP中平铺图片 文本项Repeat. 该博文中是平铺的图片,上面是文本.如果是图片add_print_image和add_print_text纯文本,这两个打印项设计的,可以直接通过 ...

  4. Android中设定背景图片平铺。

    注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 在做Android开发时,我们常常需要为程序设定一个背景,但由于现在的Android设备尺寸不一,如果随便设置一个图片为背景,那么很 ...

  5. android中可以使用bitmap的平铺,镜像平铺等减小图片带来的apk过大的问题

    bitmap的平铺.镜像drawable文件夹中新建bitmap,其中的tileMode属性 tileMode 属性就是用于定义背景的显示模式:  disabled  默认值,表示不使用平铺  cla ...

  6. ajax异步获取数据后动态向表格中添加数据(行)

    因为某些原因,项目中突然需要做自己做个ajax异步获取数据后动态向表格中添加数据的页面,网上找了半天都没有 看到现成的,决定自己写个例子 1.HTML页面 <!doctype html> ...

  7. CUBRID学习笔记 36 在net中添加多行记录

    using System.Data.Common; using CUBRID.Data.CUBRIDClient; namespace Sample { class Add_MultipleRows ...

  8. excel中添加拼接行

    Sub 万途标签()Dim iFor i = 1 To Sheets.Count    If Sheets(i).Name = "数据表" Then        If MsgBo ...

  9. 宏开发:excel中添加拼接行

    Sub 万途标签()Dim iFor i = 1 To Sheets.Count    If Sheets(i).Name = "数据表" Then        If MsgBo ...

随机推荐

  1. SPOJ Favorite Dice(概率dp)

    题意: 一个骰子,n个面,摇到每一个面的概率都一样.问你把每一个面都摇到至少一次需要摇多少次,求摇的期望次数 题解: dp[i]:已经摇到i个面,还需要摇多少次才能摇到n个面的摇骰子的期望次数 因为我 ...

  2. hdu3247Resource Archiver (AC自动机+最短路+状压dp)

    Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Submis ...

  3. jenkins:实现Jenkinsfile与Json的转换

    实现Jenkinsfile与Json的转换 目录 实现Jenkinsfile与Json的转换 方法1:使用现有的jenkins插件 参考 方法2:解析原生的jenkinsfile文件 参考 最近在做个 ...

  4. OpenStack Train版-9.安装neutron网络服务(计算节点)

    在计算节点安装neutron网络服务(computel01计算节点192.168.0.20)安装组件 yum install openstack-neutron-linuxbridge ebtable ...

  5. zoj-3870 (二进制)

    For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-m ...

  6. hdu5693D++游戏 区间DP-暴力递归

    主要的收获是..如何优化你递推式里面不必要的决策 之前的代码 这个代码在HDU超时了,这就对了..这个复杂度爆炸.. 但是这个思路非常地耿直..那就是只需要暴力枚举删两个和删三个的情况,于是就非常耿直 ...

  7. 概率分析方法与推断统计(来自我写的python书)

    在数据分析统计的场景里,常用的方法除了描述性统计方法外,还有推断统计方法,如果再从工作性质上来划分,推断统计包含了参数估计和假设验证这两方面的内容.而推断统计用到了很多概率统计方法,所以本小节在介绍推 ...

  8. NGINX configure auto generator

    NGINX configure auto generator The easiest way to configure a performant, secure, and stable NGINX s ...

  9. Web 前端必备的各种跨域方式汇总

    Web 前端必备的各种跨域方式汇总 跨域方式汇总 同源策略 协议相同 + 域名相同 + 端口相同 https://www.xgqfrms.xyz/index.html https://www.xgqf ...

  10. react-parent-child-lifecycle-order

    react-parent-child-lifecycle-order react parent child lifecycle order live demo https://33qrr.csb.ap ...