有时你需要在一个Word文档中插入一个水印,例如如果你想打印草稿文档或将其标记为机密。
在Microsoft Word中,您可以使用插入水印命令快速插入水印。没有多少人使用这个命令认识到这样的“水印”只是一个形状与文本一起插入到页眉或页脚,或在页面的中心位置。
而在Aspose.Words中,没有单一的“插入水印”命令就像Microsoft Word,它很容易将任何形状或图像插入到页眉或页脚,从而创建一个任何可以想象类型的水印。
Example
把水印插入一个Word文档。
using System; using System.Drawing; using System.IO; using System.Reflection; using Aspose.Words; using Aspose.Words.Drawing; using Aspose.Words.Fields; namespace AddWatermark { public class Program { public static void Main(string[] args) { // Sample infrastructure. string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar; string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath; Document doc = new Document(dataDir + "TestFile.doc"); InsertWatermarkText(doc, "CONFIDENTIAL"); doc.Save(dataDir + "TestFile Out.doc"); } /// <summary> /// Inserts a watermark into a document. /// </summary> /// <param name="doc">The input document.</param> /// <param name="watermarkText">Text of the watermark.</param> private static void InsertWatermarkText(Document doc, string watermarkText) { // Create a watermark shape. This will be a WordArt shape. // You are free to try other shape types as watermarks. Shape watermark = new Shape(doc, ShapeType.TextPlainText); // Set up the text of the watermark. watermark.TextPath.Text = watermarkText; watermark.TextPath.FontFamily = "Arial"; watermark.Width = 500; watermark.Height = 100; // Text will be directed from the bottom-left to the top-right corner. watermark.Rotation = -40; // Remove the following two lines if you need a solid black text. watermark.Fill.Color = Color.Gray; // Try LightGray to get more Word-style watermark watermark.StrokeColor = Color.Gray; // Try LightGray to get more Word-style watermark // Place the watermark in the page center. watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page; watermark.WrapType = WrapType.None; watermark.VerticalAlignment = VerticalAlignment.Center; watermark.HorizontalAlignment = HorizontalAlignment.Center; // Create a new paragraph and append the watermark to this paragraph. Paragraph watermarkPara = new Paragraph(doc); watermarkPara.AppendChild(watermark); // Insert the watermark into all headers of each document section. foreach (Section sect in doc.Sections) { // There could be up to three different headers in each section, since we want // the watermark to appear on all pages, insert into all headers. InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary); InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst); InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven); } } private static void InsertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, HeaderFooterType headerType) { HeaderFooter header = sect.HeadersFooters[headerType]; if (header == null) { // There is no header of the specified type in the current section, create it. header = new HeaderFooter(sect.Document, headerType); sect.HeadersFooters.Add(header); } // Insert a clone of the watermark into the header. header.AppendChild(watermarkPara.Clone(true)); } } }
Imports Microsoft.VisualBasic Imports System Imports System.Drawing Imports System.IO Imports System.Reflection Imports Aspose.Words Imports Aspose.Words.Drawing Imports Aspose.Words.Fields Namespace AddWatermark Public Class Program Public Shared Sub Main(ByVal args() As String) ' Sample infrastructure. Dim exeDir As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar Dim dataDir As String = New Uri(New Uri(exeDir), "../../Data/").LocalPath Dim doc As New Document(dataDir & "TestFile.doc") InsertWatermarkText(doc, "CONFIDENTIAL") doc.Save(dataDir & "TestFile Out.doc") End Sub ''' <summary> ''' Inserts a watermark into a document. ''' </summary> ''' <param name="doc">The input document.</param> ''' <param name="watermarkText">Text of the watermark.</param> Private Shared Sub InsertWatermarkText(ByVal doc As Document, ByVal watermarkText As String) ' Create a watermark shape. This will be a WordArt shape. ' You are free to try other shape types as watermarks. Dim watermark As New Shape(doc, ShapeType.TextPlainText) ' Set up the text of the watermark. watermark.TextPath.Text = watermarkText watermark.TextPath.FontFamily = "Arial" watermark.Width = 500 watermark.Height = 100 ' Text will be directed from the bottom-left to the top-right corner. watermark.Rotation = -40 ' Remove the following two lines if you need a solid black text. watermark.Fill.Color = Color.Gray ' Try LightGray to get more Word-style watermark watermark.StrokeColor = Color.Gray ' Try LightGray to get more Word-style watermark ' Place the watermark in the page center. watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page watermark.WrapType = WrapType.None watermark.VerticalAlignment = VerticalAlignment.Center watermark.HorizontalAlignment = HorizontalAlignment.Center ' Create a new paragraph and append the watermark to this paragraph. Dim watermarkPara As New Paragraph(doc) watermarkPara.AppendChild(watermark) ' Insert the watermark into all headers of each document section. For Each sect As Section In doc.Sections ' There could be up to three different headers in each section, since we want ' the watermark to appear on all pages, insert into all headers. InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary) InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst) InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven) Next sect End Sub Private Shared Sub InsertWatermarkIntoHeader(ByVal watermarkPara As Paragraph, ByVal sect As Section, ByVal headerType As HeaderFooterType) Dim header As HeaderFooter = sect.HeadersFooters(headerType) If header Is Nothing Then ' There is no header of the specified type in the current section, create it. header = New HeaderFooter(sect.Document, headerType) sect.HeadersFooters.Add(header) End If ' Insert a clone of the watermark into the header. header.AppendChild(watermarkPara.Clone(True)) End Sub End Class End Namespace
相关推荐
本项目聚焦于使用C#编程语言,在WPF(Windows Presentation Foundation)环境中,结合Aspose.Words.dll库来实现Word文档的水印添加以及接受修订功能。下面将详细介绍这个过程及其相关知识点。 首先,Aspose.Words....
Aspose.Words for .NET 18.7是一款强大的文档处理库,专为.NET和.NET Core框架设计,用于在各种应用程序中实现高级文档操作,包括创建、编辑、转换和渲染Microsoft Word文档。在这个版本中,重点是去水印功能,这...
描述中提到"aspose.words 18.7,亲测无水印,添加依赖 SkiaSharp, Version=1.60.1",这意味着该版本的Aspose.Words不仅没有预览或试用版通常附带的水印,而且开发团队可能已经集成了一个名为SkiaSharp的图形库。...
在使用Aspose.Words的过程中,开发人员需要引用`Aspose.Words.dll`文件,这是库的核心组件,包含了所有必需的功能。通过适当的代码引用和调用,可以轻松地实现文档处理任务。 总之,Aspose.Words 19.11是一个针对...
总的来说,这个压缩包提供了一个使用Aspose.Words库进行Word文档处理的实战示例,特别是无水印的导出功能,对于需要在项目中处理大量Word文档的开发者来说,这是一个非常有价值的资源。通过学习和理解这个demo,...
值得注意的是,这个版本还支持添加水印功能,这意味着开发者可以轻松地在导出的Word文档上添加自定义的水印,增强了文档的安全性和版权保护。 在Unity中使用Aspose.Words.dll时,首先需要确保你的Unity项目已经配置...
在实际开发中,使用Aspose.Words.dll 需要通过编程接口调用其方法。这需要具备一定的C#或其他.NET语言基础,理解DLL中的类、方法和属性,以便正确地操作Word文档。同时,开发者还需要了解如何处理可能出现的异常和...
在这个特定的案例中,"aspose-words word添加水印的jar和licence文件"是Aspose.Words的一个组件,专门用于在Word文档中添加水印功能。 水印是文档保护和标识的一种常见方法,通常用于在不遮挡文本的情况下向文档...
Java平台的开发者可以通过引入这个jar包,使用Java代码来调用Aspose.Words的相关方法,实现对Word文档水印的去除。 4. **License.xml**:在描述中提到了“license.xml”,这通常是指软件许可文件,包含了关于软件...
Aspose.Words是一款强大的文档处理库,主要用于在Java应用程序中创建、编辑和操作Microsoft Word文档。这个21.11版本的jar包是Aspose.Words的一个无水印版本,适用于那些希望在不显示任何品牌标识的情况下使用其功能...
去除了“Evaluation Only. Created with Aspose.Words. Copyright 2003-2011 Aspose Pty Ltd.”水印 word,pdf等相互转换,相信对需要的朋友有帮组
Aspose.Words是一款强大的文档处理库,主要用于在.NET环境中创建、操作和转换Microsoft Word文档。这个18.7版本的Aspose.Words以其卓越的性能和兼容性赢得了用户的高度评价,特别是其无水印功能,使得用户在处理文档...
Aspose.Words for Net破解版的类库,生成的word文档没有水印和广告等字样,附有API开发文档,在此贡献给开发者们。
在IT行业中,Aspose.Words是一款著名的文档处理库,它提供了强大的API,使得开发者能够方便地在各种应用程序中创建、编辑、转换和显示Microsoft Word文档。在这个“aspose-words_license_jar_调用方法.rar”压缩包中...
Aspose.Words提供商业许可,购买后可以在生成的文件中去除试用版的水印和广告。免费版本通常会有这些限制。 4. **解决PDF乱码问题** Aspose.Words在转换过程中,通过正确设置字符集和编码,可以避免PDF输出的乱码...
7. **无水印版本**:在描述中提到的“无水印”,意味着开发者在使用此组件生成的文档上不会出现任何Aspose的水印,可以放心用于商业项目。 8. **兼容性**:Aspose.Word.dll不仅支持.NET Framework,还支持.NET Core...
提供的`实例代码`可能是Java或.NET平台上的,它演示了如何使用Aspose.Words API在Word文档中添加水印的具体步骤。代码示例可能会包含如下的关键部分: ```java // 加载文档 Document doc = new Document("input....
Aspose.Words.dll 是一个由...总结来说,Aspose.Words.dll是.NET开发中处理Word文档的强大工具,17.7版本虽然不支持.NET Core,但在.NET Framework下依然表现出色,提供无水印的转换和处理功能,是开发中的理想选择。
要在PDF文档中添加水印,我们需要使用Aspose.Words的`WatermarkOptions`类。水印可以是文本、图像或者组合。以下是一个添加文本水印的例子: ```csharp WatermarkOptions watermarkOptions = new ...
- **创建和编辑**:Aspose.Words提供API,允许开发者在代码中创建全新的Word文档,或者打开现有文档进行编辑,添加文本、图片、表格、形状等元素。 - **格式转换**:强大的文档转换功能,能够将Word文档转换为PDF...