Word .NET库组件Spire.Doc系列教程(47):添加多行文字水印到 Word 文档

该文将介绍如何使用Spire.Doc for .NET 在Word文档中页眉中添加艺术字模拟实现Word文档中多行文字水印效果。

*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,查看折扣价!想要获取更多福利的朋友可以咨询在线客服哦~


通常情况下,Microsoft word只支持添加一个文本水印到Word文档。该文将介绍如何使用Spire.Doc for .NET 在Word文档中页眉中添加艺术字模拟实现Word文档中多行文字水印效果。

C#

using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;namespace WordWatermark{    class Program    {        static void Main(string[] args)        {            //加载示例文档            Document doc = new Document();            doc.LoadFromFile("Sample.docx");            //添加艺术字并设置大小            ShapeObject shape = new ShapeObject(doc,ShapeType.TextPlainText);            shape.Width = 60;            shape.Height = 20;            //设置艺术字文本内容、位置及样式            shape.VerticalPosition = 30;            shape.HorizontalPosition = 20;            shape.Rotation = 315;            shape.WordArt.Text = "内部使用";            shape.FillColor = System.Drawing.Color.Red;            shape.StrokeColor = System.Drawing.Color.Gray;            Section section;            HeaderFooter header;           for (int n = 0; n < doc.Sections.Count; n++) { section = doc.Sections[n]; //获取section的页眉 header = section.HeadersFooters.Header; Paragraph paragraph1; for (int i = 0; i < 3; i++) { //添加段落到页眉 paragraph1 = header.AddParagraph(); for (int j = 0; j < 4; j++) { //复制艺术字并设置多行多列位置 shape = (ShapeObject)shape.Clone(); shape.VerticalPosition = 50 + 150 * i; shape.HorizontalPosition=20 + 160 * j; paragraph1.ChildObjects.Add(shape); } } } //保存文档 doc.SaveToFile("result.docx", FileFormat.Docx2013); System.Diagnostics.Process.Start("result.docx"); } } }

VB.NET

Class Program    Private Shared Sub Main(ByVal args As String())        Dim doc As Document = New Document()        doc.LoadFromFile("Sample.docx")        Dim shape As ShapeObject = New ShapeObject(doc, ShapeType.TextPlainText)        shape.Width = 60        shape.Height = 20        shape.VerticalPosition = 30        shape.HorizontalPosition = 20        shape.Rotation = 315        shape.WordArt.Text = "内部使用"        shape.FillColor = System.Drawing.Color.Red        shape.StrokeColor = System.Drawing.Color.Gray        Dim section As Section        Dim header As HeaderFooter        For n As Integer = 0 To doc.Sections.Count - 1            section = doc.Sections(n)            header = section.HeadersFooters.Header            Dim paragraph1 As Paragraph            For i As Integer = 0 To 3 - 1                paragraph1 = header.AddParagraph()                For j As Integer = 0 To 4 - 1                    shape = CType(shape.Clone(), ShapeObject)                    shape.VerticalPosition = 50 + 150 * i                    shape.HorizontalPosition = 20 + 160 * j                    paragraph1.ChildObjects.Add(shape)                Next            Next        Next        doc.SaveToFile("result.docx", FileFormat.Docx2013)    End SubEnd Class

多行多列文本水印效果图:

Word .NET库组件Spire.Doc系列教程(47):添加多行文字水印到 Word 文档

推荐阅读:【想要快速完成文档格式转换吗pire系列组件格式转换完整攻略来啦!】


还想要更多吗可以点击阅读【2020 · E-iceblue最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时联系客服,我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年8月5日
下一篇 2020年8月5日

相关推荐

发表回复

登录后才能评论