-
Notifications
You must be signed in to change notification settings - Fork 0
/
HeaderAndFooterActions.cs
45 lines (44 loc) · 1.87 KB
/
HeaderAndFooterActions.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
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DXRichEditControlAPISample.CodeExamples
{
class HeaderAndFooterActions
{
static void CreateHeader(Document document)
{
#region #CreateHeader
Section firstSection = document.Sections[0];
// Create an empty header.
SubDocument newHeader = firstSection.BeginUpdateHeader();
firstSection.EndUpdateHeader(newHeader);
// Check whether the document already has a header (the same header for all pages).
if (firstSection.HasHeader(HeaderFooterType.Primary))
{
SubDocument headerDocument = firstSection.BeginUpdateHeader();
document.ChangeActiveDocument(headerDocument);
document.CaretPosition = headerDocument.CreatePosition(0);
firstSection.EndUpdateHeader(headerDocument);
}
#endregion #CreateHeader
}
static void ModifyHeader(Document document)
{
#region #ModifyHeader
document.AppendSection();
Section firstSection = document.Sections[0];
// Modify the header of the HeaderFooterType.First type.
SubDocument myHeader = firstSection.BeginUpdateHeader(HeaderFooterType.First);
DocumentRange range = myHeader.InsertText(myHeader.CreatePosition(0), " PAGE NUMBER ");
Field fld = myHeader.Fields.Create(range.End, "PAGE \\* ARABICDASH");
myHeader.Fields.Update();
firstSection.EndUpdateHeader(myHeader);
// Display the header of the HeaderFooterType.First type on the first page.
firstSection.DifferentFirstPage = true;
#endregion #ModifyHeader
}
}
}