在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. AtCoder Beginner Contest 171

    比赛链接:https://atcoder.jp/contests/abc171/tasks A - αlphabet 题意 给出一个字母,如果为大写输出 'A',如果为小写输出 'a' . 代码 #i ...

  2. 【51nod1674】区间的价值 V2(算法效率--位运算合并优化+链表实现)

    题目链接:  51nod1674 题意:规定一个区间的价值为这个区间中所有数and起来的值与这个区间所有数or起来的值的乘积.现在l有一个 N 个数的序列,问所有n*(n+1)/2个区间的贡献的和对1 ...

  3. hdu3555 Bomb(要49)

    Problem Description The counter-terrorists found a time bomb in the dust. But this time the terroris ...

  4. 牛客小白月赛17 G 区间求和

    传送门 题意: 题解: 原本想着使用暴力方法: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream& ...

  5. Intelligent IME HDU - 4287 字典树

    题意: 给你m个字符串,每一个字符对应一个数字,如下: 2 : a, b, c    3 : d, e, f    4 : g, h, i    5 : j, k, l    6 : m, n, o ...

  6. EFCore学习记录--数据访问技术人门

    1.安装Microsoft.EntityFrameworkCore.Sqlite.Microsoft.EntityFrameworkCore.Tools包2.创建模型 数据库上下文模型:Bloggin ...

  7. rabbitmq常见面试题

    1.使用RabbitMQ有什么好处?1.解耦,系统A在代码中直接调用系统B和系统C的代码,如果将来D系统接入,系统A还需要修改代码,过于麻烦! 2.异步,将消息写入消息队列,非必要的业务逻辑以异步的方 ...

  8. 梨子带你刷burp练兵场(burp Academy) - 服务器篇 - Sql注入 - SQL injection UNION attack, determining the number of columns returned by the query

    目录 SQL injection UNION attack, determining the number of columns returned by the query SQL injection ...

  9. RuntimeError already started

    Env: os: Ubuntu python3 pytorch vscode Desc 在上述环境中运行A3C多进程模型,使用命令行时没问题,使用vscode时出现 'RuntimeError: al ...

  10. java-GUI编程学习总结

    狂神说java-GUI编程学习总结 1.简介 2.AWT 2.1.实现如图1-2 (1)面向过程写法 (2)内部类写法 (3)完全改造成面向对象 3.Swing 3.1.鼠标花点 3.2.弹窗 3.3 ...