HeaderFooterType Enumeration |
Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.7.18
Syntax public enum HeaderFooterType
Public Enumeration HeaderFooterType
Members Member name | Value | Description |
---|
HeaderDefault | 0 |
Default header.
|
HeaderEven | 1 |
Header for even pages.
|
HeaderFirst | 2 |
Header for the first page in section.
|
FooterDefault | 3 |
Default footer.
|
FooterEven | 4 |
Footer for even pages.
|
FooterFirst | 5 |
Footer for the first page in section.
|
Example See Developer Guide: Create a document with different headers: on first page, default and in another section
Create a document with different headers: on first page, default and in another section using C#
using System;
using System.IO;
using SautinSoft.Document;
namespace Example
{
class Program
{
static void Main(string[] args)
{
DifferentHeaderAndFooters();
}
static void DifferentHeaderAndFooters()
{
string documentPath = "DifferentHeaders.docx";
DocumentCore dc = new DocumentCore();
Section section1 = new Section(dc);
dc.Sections.Add(section1);
HeaderFooter defaultHeader = CreateDefaultHeader(dc);
HeaderFooter firstHeader = CreateFirstHeader(dc);
section1.HeadersFooters.Add(defaultHeader);
section1.HeadersFooters.Add(firstHeader);
section1.PageSetup.TitlePage = true;
Paragraph p = new Paragraph(dc, "My father\'s family name being Pirrip, and my Christian name Philip, " +
"my infant tongue could make of both names nothing longer or more explicit than Pip. So, I called myself " +
"Pip, and came to be called Pip. I give Pirrip as my father\'s family name, on the authority of his " +
"tombstone and my sister, -Mrs. Joe Gargery, who married the blacksmith.");
int totalPars = 15;
for (int i = 0; i < totalPars; i++)
{
section1.Blocks.Add(p.Clone(true));
}
Section section2 = new Section(dc);
dc.Sections.Add(section2);
HeaderFooter header = new HeaderFooter(dc, HeaderFooterType.HeaderDefault);
header.Content.Start.Insert("Chapter II - another header.", new CharacterFormat()
{
FontColor = Color.Blue,
Size = 18
});
section2.HeadersFooters.Add(header);
section2.Content.Start.Insert("My sister, Mrs. Joe Gargery, was more than twenty years older than I, " +
"and had established a great reputation with herself and the neighbors because she had brought me " +
"up \"by hand.\" Having at that time to find out for myself what the expression meant, and knowing " +
"her to have a hard and heavy hand, and to be much in the habit of laying it upon her husband as well " +
"as upon me, I supposed that Joe Gargery and I were both brought up by hand.");
dc.Save(documentPath);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
}
static HeaderFooter CreateDefaultHeader(DocumentCore dc)
{
HeaderFooter header = new HeaderFooter(dc, HeaderFooterType.HeaderDefault);
header.Content.Start.Insert("Chapter I - This is the default header", new CharacterFormat()
{
FontName = "Verdana",
Size = 18.0,
FontColor = Color.Orange
});
return header;
}
static HeaderFooter CreateFirstHeader(DocumentCore dc)
{
HeaderFooter header = new HeaderFooter(dc, HeaderFooterType.HeaderFirst);
header.Content.Start.Insert("Charles Dickens. Great Expectations - 1st page header", new CharacterFormat()
{
FontName = "Verdana",
Size = 18.0,
FontColor = Color.DarkGreen
});
return header;
}
}
}
Create a document with different headers: on first page, default and in another section using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Namespace Example
Friend Class Program
Shared Sub Main(ByVal args() As String)
DifferentHeaderAndFooters()
End Sub
Private Shared Sub DifferentHeaderAndFooters()
Dim documentPath As String = "DifferentHeaders.docx"
Dim dc As New DocumentCore()
Dim section1 As New Section(dc)
dc.Sections.Add(section1)
Dim defaultHeader As HeaderFooter = CreateDefaultHeader(dc)
Dim firstHeader As HeaderFooter = CreateFirstHeader(dc)
section1.HeadersFooters.Add(defaultHeader)
section1.HeadersFooters.Add(firstHeader)
section1.PageSetup.TitlePage = True
Dim p As New Paragraph(dc, "My father's family name being Pirrip, and my Christian name Philip, " & "my infant tongue could make of both names nothing longer or more explicit than Pip. So, I called myself " & "Pip, and came to be called Pip. I give Pirrip as my father's family name, on the authority of his " & "tombstone and my sister, -Mrs. Joe Gargery, who married the blacksmith.")
Dim totalPars As Integer = 15
For i As Integer = 0 To totalPars - 1
section1.Blocks.Add(p.Clone(True))
Next i
Dim section2 As New Section(dc)
dc.Sections.Add(section2)
Dim header As New HeaderFooter(dc, HeaderFooterType.HeaderDefault)
header.Content.Start.Insert("Chapter II - another header.", New CharacterFormat() With {
.FontColor = Color.Blue,
.Size = 18
})
section2.HeadersFooters.Add(header)
section2.Content.Start.Insert("My sister, Mrs. Joe Gargery, was more than twenty years older than I, " & "and had established a great reputation with herself and the neighbors because she had brought me " & "up ""by hand."" Having at that time to find out for myself what the expression meant, and knowing " & "her to have a hard and heavy hand, and to be much in the habit of laying it upon her husband as well " & "as upon me, I supposed that Joe Gargery and I were both brought up by hand.")
dc.Save(documentPath)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
End Sub
Private Shared Function CreateDefaultHeader(ByVal dc As DocumentCore) As HeaderFooter
Dim header As New HeaderFooter(dc, HeaderFooterType.HeaderDefault)
header.Content.Start.Insert("Chapter I - This is the default header", New CharacterFormat() With {
.FontName = "Verdana",
.Size = 18.0,
.FontColor = Color.Orange
})
Return header
End Function
Private Shared Function CreateFirstHeader(ByVal dc As DocumentCore) As HeaderFooter
Dim header As New HeaderFooter(dc, HeaderFooterType.HeaderFirst)
header.Content.Start.Insert("Charles Dickens. Great Expectations - 1st page header", New CharacterFormat() With {
.FontName = "Verdana",
.Size = 18.0,
.FontColor = Color.DarkGreen
})
Return header
End Function
End Class
End Namespace
See Also