当前位置:网站首页>C how to set different text watermarks for each page of word
C how to set different text watermarks for each page of word
2022-07-27 04:06:00 【Yisu cloud】
C# How to give Word Set different text watermarks on each page
This article mainly explains “C# How to give Word Set different text watermarks on each page ”, The explanation in the text is simple and clear , Easy to learn and understand , Next, please follow Xiaobian's ideas and go deeper slowly , Study and learn together “C# How to give Word Set different text watermarks on each page ” Well !
Way of thinking
In giving Word Before adding text watermark to each page , The first thing you need to do is Word file Every page After the last character of the body Insert “ continuity ” Section break , And then in Add WordArt shapes to the header paragraphs of each section , And set the shape size 、 Alignment, etc . Last save document .
dll quote
Method 1
Introduce... Into the program Spire.Doc.dll file ; take Spire.Doc for .NET Download to local , decompression , find BIN Under folder Spire.Doc.dll. And then in Visual Studio Open in “ Solution explorer ”, Right click “ quote ”,“ Add reference ”, The local path BIN Under folder dll Add a reference to the program .
Method 2
adopt NuGet install . This can be done by 2 Methods of installation :
1. Can be in Visual Studio Open in “ Solution explorer ”, Right click “ quote ”,“ management NuGet package ”, And then the search “Spire.Doc”, Click on “ install ”. Wait for the program installation to complete .
2. Copy the following to PM Console installation .
Install-Package Spire.Doc -Version 10.1.14
Code example
When adding text watermark to each page , Please refer to the following steps :
establish Document Class object , And pass LoadFromFile(string fileName) Method loading Word file .
adopt Document.Sections[] Property to get the specified section .
adopt HeadersFooters.Header Property to get the header ,HeaderFooter.AddParagraph() Method to add a paragraph to the header .
establish ShapeObject Class object , And pass in parameters to set the shape type to TextPlainText Type of artistic characters . And call the method to set the WordArt style , Such as the height of artistic characters 、 Width 、 rotate 、 Color 、 Alignment, etc .
Use DocumentObjectCollection.Add(IDocumentObject) Method to add WordArt to a paragraph .
Last , adopt Document.SaveToFile(string fileName, FileFormat fileFormat) Method to save a document .
Different text watermark effects are set in different pages , Just get the section corresponding to the page , Then refer to the method used above to add .
C#
using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;using System.Drawing;namespace TextWatermark2{ class Program { static void Main(string[] args) { // load Word Test documentation Document doc = new Document(); doc.LoadFromFile("test.docx"); // Get the first section of the document Section section1 = doc.Sections[0]; // Define the vertical coordinate position of the watermark text float y = section1.PageSetup.PageSize.Height/3; // Add text watermark 1 HeaderFooter header1 = section1.HeadersFooters.Header;// Get header header1.Paragraphs.Clear();// Delete the original header format paragraph Paragraph para1 = header1.AddParagraph();// Re add paragraph // Add WordArt and set the size ShapeObject shape1 = new ShapeObject(doc, ShapeType.TextPlainText); shape1.Width = 362; shape1.Height = 118; // Set WordArt text content 、 Location and style ( That is, text watermark ) shape1.Rotation = 315; shape1.WordArt.Text = " For internal use "; shape1.FillColor = Color.ForestGreen; shape1.LineStyle = ShapeLineStyle.Single; shape1.StrokeColor = Color.ForestGreen; shape1.StrokeWeight = 0.5; shape1.VerticalPosition = y; shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center; para1.ChildObjects.Add(shape1); // Similarly, set the text watermark in the header of section 2 2 Section section2 = doc.Sections[1]; HeaderFooter header2 = section2.HeadersFooters.Header; header2.Paragraphs.Clear(); Paragraph para2 = header2.AddParagraph(); ShapeObject shape2 = new ShapeObject(doc, ShapeType.TextPlainText); shape2.Width = 362; shape2.Height = 118; shape2.Rotation = 315; shape2.WordArt.Text = " Top secret information "; shape2.FillColor = Color.HotPink; shape2.LineStyle = ShapeLineStyle.Single; shape2.StrokeColor = Color.HotPink; shape2.StrokeWeight = 0.5; shape2.VerticalPosition = y; shape2.HorizontalAlignment = ShapeHorizontalAlignment.Center; para2.ChildObjects.Add(shape2); // Similarly, set the text watermark in the header in Section 3 3 Section section3 = doc.Sections[2]; HeaderFooter header3 = section3.HeadersFooters.Header; header3.Paragraphs.Clear(); Paragraph para3 = header3.AddParagraph(); ShapeObject shape3 = new ShapeObject(doc, ShapeType.TextPlainText); shape3.Width = 362; shape3.Height = 118; shape3.Rotation = 315; shape3.WordArt.Text = " No circulation "; shape3.FillColor = Color.DarkOrange; shape3.LineStyle = ShapeLineStyle.Single; shape3.StrokeColor = Color.DarkOrange; shape3.StrokeWeight = 0.5; shape3.VerticalPosition = y; shape3.HorizontalAlignment = ShapeHorizontalAlignment.Center; para3.ChildObjects.Add(shape3); // Save the document doc.SaveToFile("DifferentTextWatermark.docx", FileFormat.Docx2013); System.Diagnostics.Process.Start("DifferentTextWatermark.docx"); } }}VB.NET
Imports Spire.DocImports Spire.Doc.DocumentsImports Spire.Doc.FieldsImports System.DrawingNamespace TextWatermark2 Class Program Private Shared Sub Main(args As String()) ' load Word Test documentation Dim doc As New Document() doc.LoadFromFile("test.docx") ' Get the first section of the document Dim section1 As Section = doc.Sections(0) ' Define the vertical coordinate position of the watermark text Dim y As Single = section1.PageSetup.PageSize.Height / 3 ' Add text watermark 1 Dim header1 As HeaderFooter = section1.HeadersFooters.Header ' Get header header1.Paragraphs.Clear() ' Delete the original header format paragraph Dim para1 As Paragraph = header1.AddParagraph() ' Re add paragraph ' Add WordArt and set the size Dim shape1 As New ShapeObject(doc, ShapeType.TextPlainText) shape1.Width = 362 shape1.Height = 118 ' Set WordArt text content 、 Location and style ( That is, text watermark ) shape1.Rotation = 315 shape1.WordArt.Text = " For internal use " shape1.FillColor = Color.ForestGreen shape1.LineStyle = ShapeLineStyle.[Single] shape1.StrokeColor = Color.ForestGreen shape1.StrokeWeight = 0.5 shape1.VerticalPosition = y shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center para1.ChildObjects.Add(shape1) ' Similarly, set the text watermark in the header of section 2 2 Dim section2 As Section = doc.Sections(1) Dim header2 As HeaderFooter = section2.HeadersFooters.Header header2.Paragraphs.Clear() Dim para2 As Paragraph = header2.AddParagraph() Dim shape2 As New ShapeObject(doc, ShapeType.TextPlainText) shape2.Width = 362 shape2.Height = 118 shape2.Rotation = 315 shape2.WordArt.Text = " Top secret information " shape2.FillColor = Color.HotPink shape2.LineStyle = ShapeLineStyle.[Single] shape2.StrokeColor = Color.HotPink shape2.StrokeWeight = 0.5 shape2.VerticalPosition = y shape2.HorizontalAlignment = ShapeHorizontalAlignment.Center para2.ChildObjects.Add(shape2) ' Similarly, set the text watermark in the header in Section 3 3 Dim section3 As Section = doc.Sections(2) Dim header3 As HeaderFooter = section3.HeadersFooters.Header header3.Paragraphs.Clear() Dim para3 As Paragraph = header3.AddParagraph() Dim shape3 As New ShapeObject(doc, ShapeType.TextPlainText) shape3.Width = 362 shape3.Height = 118 shape3.Rotation = 315 shape3.WordArt.Text = " No circulation " shape3.FillColor = Color.DarkOrange shape3.LineStyle = ShapeLineStyle.[Single] shape3.StrokeColor = Color.DarkOrange shape3.StrokeWeight = 0.5 shape3.VerticalPosition = y shape3.HorizontalAlignment = ShapeHorizontalAlignment.Center para3.ChildObjects.Add(shape3) ' Save the document doc.SaveToFile("DifferentTextWatermark.docx", FileFormat.Docx2013) System.Diagnostics.Process.Start("DifferentTextWatermark.docx") End Sub End ClassEnd NamespacePictured , Each page can display different text watermark effects :

Thank you for reading , That's all “C# How to give Word Set different text watermarks on each page ” Content. , After learning this article , I'm sure you're right C# How to give Word We have a deeper understanding of the problem of setting different text watermarks on each page , The specific use needs to be verified by practice . This is billion speed cloud , Xiaobian will push you articles with more relevant knowledge points , Welcome to your attention !
边栏推荐
- Kotlin中lateinit和lazy的原理区别是什么
- mysql中case when返回多个字段处理方案
- Abstract intelligent extraction [based on Bert technology]
- 科目三: 济南章丘6号线
- 288 page 180000 word intelligent campus overall design directory
- The job created by flinksqlclient will disappear after the restart of Flink. Is there any way?
- 科目三: 济南章丘二号线
- C语言入门实战(12):求自然常数e的值
- Golang JWT cross domain authentication
- Plato farm has a new way of playing, and the arbitrage eplato has secured super high returns
猜你喜欢

基于风能转换系统的非线性优化跟踪控制(Matlab代码实现)

阿里云服务器域名加端口网页不能访问问题记录

电商系统结合商品秒杀活动,VR全景不断带来收益

Restful Fast Request 2022.2.2发布,支持批量导出文档

Golang sends email to the mail Library

288页18万字智能化校园总体设计 目录

Skywalking distributed system application performance monitoring tool - medium

2022危险化学品生产单位安全生产管理人员考试题模拟考试题库模拟考试平台操作

Chapter 4 decision tree and random forest

222. Number of nodes of complete binary tree
随机推荐
3381. 手机键盘(清华大学考研机试题)
First pass of routing strategy
科目三: 济南章丘二号线
Redis database, which can be understood by zero foundation Xiaobai, is easy to learn and use!
288页18万字智能化校园总体设计 目录
Regression testing: meaning, challenges, best practices and tools
ApacheCon Asia 预热直播之孵化器主题全回顾
Summer meal | rich people are different from what you think (day 5) + power system power flow simulation (documents and matlab code)
JS array de duplication (including simple array de duplication and object array de duplication)
NFT数字藏品系统开发:老牌文学杂志玩起新潮数字藏品
Kotlin中lateinit和lazy的原理区别是什么
VR全景制作在家装行业是谈单利器?这是为什么呢?
jmeter接口测试(登录、注册)
Chapter 4 decision tree and random forest
2022年危险化学品经营单位主要负责人复训题库及答案
Implementation of API short message gateway based on golang
三种常见的移动底盘运动学模型分析
leetcode:433. 最小基因变化
函数指针与回调函数
Process analysis of object creation