-
Notifications
You must be signed in to change notification settings - Fork 9
/
WatermarkActions.cs
68 lines (62 loc) · 2.74 KB
/
WatermarkActions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RichEditDocumentServerAPIExample.CodeExamples
{
class WatermarkActions
{
public static Action<RichEditDocumentServer> CreateTextWatermarkAction = CreateTextWatermark;
public static Action<RichEditDocumentServer> CreateImageWatermarkAction = CreateImageWatermark;
static void CreateTextWatermark(RichEditDocumentServer wordProcessor)
{
#region #CreateTextWatermark
// Access a document.
Document document = wordProcessor.Document;
// Check whether the document sections have headers.
foreach (Section section in document.Sections)
{
if (!section.HasHeader(HeaderFooterType.Primary))
{
// Create an empty header.
SubDocument header = section.BeginUpdateHeader();
section.EndUpdateHeader(header);
}
}
// Specify text watermark options.
TextWatermarkOptions textWatermarkOptions = new TextWatermarkOptions();
textWatermarkOptions.Color = System.Drawing.Color.LightGray;
textWatermarkOptions.FontFamily = "Calibri";
textWatermarkOptions.Layout = WatermarkLayout.Horizontal;
textWatermarkOptions.Semitransparent = true;
// Add a text watermark to all document pages.
document.WatermarkManager.SetText("CONFIDENTIAL", textWatermarkOptions);
#endregion #CreateTextWatermark
}
static void CreateImageWatermark(RichEditDocumentServer wordProcessor)
{
#region #CreateImageWatermark
//Check whether the document sections have headers.
foreach (Section section in wordProcessor.Document.Sections)
{
if (!section.HasHeader(HeaderFooterType.Primary))
{
// Create an empty header.
SubDocument header = section.BeginUpdateHeader();
section.EndUpdateHeader(header);
}
}
// Specify image watermark options.
ImageWatermarkOptions imageWatermarkOptions = new ImageWatermarkOptions();
imageWatermarkOptions.Washout = false;
imageWatermarkOptions.Scale = 2;
// Add an image watermark to all document pages.
wordProcessor.Document.WatermarkManager.SetImage(Image.FromFile("Documents//DevExpress.png"), imageWatermarkOptions);
#endregion #CreateImageWatermark
}
}
}