当前位置:网站首页>C#/VB.NET 添加多行多列图片水印到Word文档
C#/VB.NET 添加多行多列图片水印到Word文档
2022-08-02 10:27:00 【51CTO】
在Word里面添加水印时,常见的情况是仅支持对整个页面添加一个水印效果;对于需要将水印铺满整个页面的效果则可以参考本文中的方法。本文介绍一种比较灵活的方式实现添加多行多列(平铺)图片水印到Word文档。下面是详细方法及步骤。
环境配置
引入Word API-Free Spire.Doc for .NET( Spire.Doc.dll)
1. 通过 NuGet引入dll(2种方法)的方法
(1)可以在Visual Studio中打开“解决方案资源管理器”,鼠标右键点击“引用”,“管理NuGet包”,然后搜索“Free Spire.Doc”,点击“安装”。等待程序安装完成。
(2)将以下内容复制到PM控制台安装:
2. 手动添加dll引用的方法
可通过手动 下载包到本地,然后解压,找到BIN文件夹下的Spire.Doc.dll。然后在Visual Studio中打开“解决方案资源管理器”,鼠标右键点击“引用”,“添加引用”,将本地路径BIN文件夹下的dll文件添加引用至程序。
添加多行多列图片水印
实现多行多列图片水印效果,即在页眉处添加图片,并通过多次复制图片来模拟将水印铺满整个页面的效果,根据横向复制或者纵向复制的不同图片数量,可任意调整水印图片在页面中的分布效果。以下,是本次实现图片水印的主要代码步骤:
- 创建Document类的对象,并通过Document.LoadFromFile(string fileName)方法加载Word文档。
- for循环文档中的所有Section,并通过Document.Sections[int Index]属性获取页面中的节。
- 使用HeadersFooters.Header属性获取页眉,并通过HeaderFooter.AddParagraph()方法添加段落到页眉。
- 创建DocPicture类的对象,并调用DocPicture.LoadImage(string imgFile)方法加载水印图片,以及通过TextWrappingStyle枚举值设置图片环绕方式。
- 通过for循环以DocPicture.Clone()方法多次复制图片,并通过DocPicture.VerticalPosition和DocPicture.HorizontalPosition属性设置图片位置排列。
- 调用Paragraph.ChildObjects.Add(IDocumentObject entity)方法添加图片到页眉段落。
- 最后,通过Document.SaveToFile(string fileName, FileFormat fileFormat)方法保存文档都指定路径。
C#
VB.NET

—END—
边栏推荐
- [Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!
- LayaBox---TypeScript---Mixins
- The ggline function of the R language ggpubr package visualizes grouped line graphs, the add parameter is mean_se and dotplot to visualize line graphs of different level averages, and adds error bars
- 身为程序猿——谷歌浏览器的这些骚操作你真的废吗!【熬夜整理&建议收藏】[通俗易懂]
- 从零开始Blazor Server(5)--权限验证
- R language time series data arithmetic operation: use the log function to log the time series data, and use the diff function to calculate the successive difference of the logarithmic time series data
- List-based queuing and calling system
- 第十七章 Excel操作
- 初探zend引擎
- qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
猜你喜欢

周杰伦新歌发布,爬取《Mojito》MV弹幕,看看粉丝们都说的些啥!

Verilog's random number system task----$random

斯皮尔曼相关系数

新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!

After 21 years of graduation, I switched to software testing. From 0 income to a monthly salary of over 10,000, I am really lucky...

如何搭建威纶通触摸屏与S7-200smart之间无线PPI通信?

软件测试X模型

Verilog的随机数系统任务----$random

读博一年后对机器学习工程的思考

bgp与mpls综合实验
随机推荐
LayaBox---TypeScript---Namespaces and modules
npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
Hello, my new name is "Bronze Lock/Tongsuo"
身为程序猿——谷歌浏览器的这些骚操作你真的废吗!【熬夜整理&建议收藏】[通俗易懂]
DirectX修复工具增强版「建议收藏」
3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
MySQL百万数据优化总结 一
软件测试的基本理论知识(软件测试面试基础知识)
LayaBox---TypeScript---声明合并
mysql清除binlog日志文件
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the stacked bar plot, the lab.pos parameter specifies the position of the numerical label of the bar cha
Shell script realizes multi-select DNS simultaneous batch resolution of domain name IP addresses (new update)
4年手工测试被应届生取代了,用血与泪的教训给xdm一个忠告,该学自动化了...
如何安装dosbox(pycharm详细安装教程)
R语言时间序列数据的平滑:使用KernSmooth包的dpill函数和locpoly函数对时间序列数据进行平滑以消除噪声
全方位剖析Numpy中的np.diag源代码
Oracle超全SQL,细节狂魔
LayaBox---TypeScript---命名空间和模块
使用较广泛的安全测试工具有哪些?
牛客刷题——剑指offer(第三期)