没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|使用教程|编辑:龚雪|2015-09-02 09:19:10.000|阅读 3077 次
概述:使用Aspose.Words在文档中如何插入水印
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
有时你需要在一个Word文档中插入一个水印,例如如果你想打印草稿文档或将其标记为机密。
在Microsoft Word中,您可以使用插入水印命令快速插入水印。没有多少人使用这个命令认识到这样的“水印”只是一个形状与文本一起插入到页眉或页脚,或在页面的中心位置。
而在Aspose.Words中,没有单一的“插入水印”命令就像Microsoft Word,它很容易将任何形状或图像插入到页眉或页脚,从而创建一个任何可以想象类型的水印。
Example
把水印插入一个Word文档。
C# 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)); } } }
Visual Basic 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
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@dpuzeg.cn
文章转载自:慧都控件网在 Excel 中,工作表名称通常能够反映其用途或所含内容,提取这些名称有助于理清整个工作簿的结构。对于新用户或协作者来说,仅凭这些名称就能快速掌握各表中的数据类型。本文将演示如何使用 Java 获取 Excel 文件中的所有工作表名称,帮助你更高效地管理和理解工作簿数据。
本文主要介绍如何使用DevExpress WPF Grid控件中如何获取行句柄,欢迎下载最新版组件体验!
Microsoft Excel 允许您通过选择数据透视表,然后单击“插入”>“时间轴”来创建时间轴。Aspose.Cells 则还可允许您使用Worksheet.Timelines.Add()方法创建时间轴 。
本教程演示DevExpress WinForms的Banded Grid View 是如何进行用户自定义的,欢迎下载最新版组件体验!
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@dpuzeg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢