Aspose.Words給word文檔加水印

来源:http://www.cnblogs.com/johsan/archive/2017/09/12/7510749.html
-Advertisement-
Play Games

需求:在一些重要的Word文檔需要列印時,添加水印以明出處。 方案:使用Aspose組件給word文檔 代碼:乾貨如下 /// <summary> /// Inserts a watermark into a document. /// </summary> /// <param name="doc ...


        需求:在一些重要的Word文檔需要列印時,添加水印以明出處。

        方案:使用Aspose組件給word文檔

        代碼:乾貨如下

 

/// <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.
Aspose.Words.Drawing.Shape watermark = new Aspose.Words.Drawing.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 = System.Drawing.Color.Gray; // Try LightGray to get more Word-style watermark
watermark.StrokeColor = System.Drawing.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));
}


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • RemoteAttribute是asp.net mvc 的一個驗證特性,它位於System.Web.Mvc命名空間 下麵通過例子來說明 很多系統中都有會員這個功能,會員在前臺註冊時,用戶名不能與現有的用戶名重覆,還要求輸入手機號碼去註冊,同時手機號碼也需要驗證是否重覆,下麵是實體類 /// <sum ...
  • 安裝軟體的最佳實踐 雖然我們知道Linux下安裝軟體有三種方式,分別是源代碼安裝,rpm包安裝和yum安裝,但是從可控性和結合自己目前的水平來說,優先選擇以下兩種方式安裝程式。 1,使用rpm包安裝 一般是先在windows下下載好對應的rpm包,然後通過WinSCP工具copy到Linux伺服器上 ...
  • asp.net.core教程(翻譯自微軟官方文檔https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-controller)本教程會教你使用vs2017去搭建基礎的asp.net.core服務程式。本教 ...
  • MaxPageSize -此值控制的最大獨立的每個返回的對象的大小對單個搜索結果中返回的對象數。要執行的搜索的結果可能超過此數目的對象,客戶端必須指定分頁的搜索控制項。這是在不大於MaxPageSize值的組中返回的結果進行分組。總之, MaxPageSize控制在單個搜索結果中返回的對象的數目。預設 ...
  • Windows Service簡介: 一個Windows服務程式是在Windows操作系統下能完成特定功能的可執行的應用程式。Windows服務程式雖然是可執行的,但是它不像一般的可執行文件通過雙擊就能開始運行了,它必須有特定的啟動方式。這些啟動方式包括了自動啟動和手動啟動兩種。對於自動啟動的Win ...
  • 一. Ubuntu 14.04 安裝 1.安裝之前請先刪除之前的.net core 版本 命令如下: 1.1 獲取安裝的.net core 版本 sudo apt --installed list | grep "dotnet-dev" 1.2 刪除安裝的.net core 版本 sudo apt- ...
  • 在Entity Framework Core 2.0中增加一個很酷的功能:EF.Functions.Like(),最終解析為SQL中的 Like 語句,以便於在 LINQ 查詢中直接調用。不過Entity Framework 中預設提供了 StartsWith、Contains 和 EndsWith... ...
  • 如果需要調試 WPF 源代碼或框架源代碼,那麼需要使用 DotPeek ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...