Represents a header or footer; allows to operate with headers and footers.
Inheritance Hierarchy Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.12.16
Syntax public sealed class HeaderFooter : Element,
IContentElement
Public NotInheritable Class HeaderFooter
Inherits Element
Implements IContentElement
The HeaderFooter type exposes the following members.
Constructors Properties Methods Example See Developer Guide: How to add a header and footer in the document
How to add a header and footer in the document using C#
using SautinSoft.Document;
using SautinSoft.Document.Drawing;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
HeadersAndFooters();
}
public static void HeadersAndFooters()
{
string documentPath = @"HeadersAndFooters.docx";
DocumentCore dc = new DocumentCore();
Section s = new Section(dc);
dc.Sections.Add(s);
Paragraph p = new Paragraph(dc);
dc.Sections[0].Blocks.Add(p);
p.ParagraphFormat.Alignment = HorizontalAlignment.Justify;
p.Content.Start.Insert("Once upon a time, in a far away swamp, there lived an ogre named Shrek whose precious " +
"solitude is suddenly shattered by an invasion of annoying fairy tale characters...", new CharacterFormat() { Size = 12, FontName = "Arial" });
HeaderFooter header = new HeaderFooter(dc, HeaderFooterType.HeaderDefault);
header.Content.Start.Insert("Shrek and Donkey travel to the castle and split up to find Fiona.", new CharacterFormat() { Size = 14.0 });
s.HeadersFooters.Add(header);
HeaderFooter footer = new HeaderFooter(dc, HeaderFooterType.FooterDefault);
Paragraph par = new Paragraph(dc);
par.Content.Start.Insert("Shrek and Donkey travel to the castle and split up to find Fiona. ", new CharacterFormat() { Size = 14.0 });
par.ParagraphFormat.Alignment = HorizontalAlignment.Left;
double wPt = LengthUnitConverter.Convert(7, LengthUnit.Centimeter, LengthUnit.Point);
double hPt = LengthUnitConverter.Convert(7, LengthUnit.Centimeter, LengthUnit.Point);
Picture pict = new Picture(dc, Layout.Inline(new Size(wPt, hPt)), @"..\..\..\image1.jpg");
par.Inlines.Add(pict);
footer.Blocks.Add(par);
s.HeadersFooters.Add(footer);
dc.Save(documentPath);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
}
}
}
How to add a header and footer in the document using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing
Module Sample
Sub Main()
HeadersAndFooters()
End Sub
Sub HeadersAndFooters()
Dim documentPath As String = "HeadersAndFooters.docx"
Dim dc As New DocumentCore()
Dim s As New Section(dc)
dc.Sections.Add(s)
Dim p As New Paragraph(dc)
dc.Sections(0).Blocks.Add(p)
p.ParagraphFormat.Alignment = HorizontalAlignment.Justify
p.Content.Start.Insert("Once upon a time, in a far away swamp, there lived an ogre named Shrek whose precious " & "solitude is suddenly shattered by an invasion of annoying fairy tale characters...", New CharacterFormat() With {
.Size = 12,
.FontName = "Arial"
})
Dim header As New HeaderFooter(dc, HeaderFooterType.HeaderDefault)
header.Content.Start.Insert("Shrek and Donkey travel to the castle and split up to find Fiona.", New CharacterFormat() With {.Size = 14.0})
s.HeadersFooters.Add(header)
Dim footer As New HeaderFooter(dc, HeaderFooterType.FooterDefault)
Dim par As New Paragraph(dc)
par.Content.Start.Insert("Shrek and Donkey travel to the castle and split up to find Fiona. ", New CharacterFormat() With {.Size = 14.0})
par.ParagraphFormat.Alignment = HorizontalAlignment.Left
Dim wPt As Double = LengthUnitConverter.Convert(7, LengthUnit.Centimeter, LengthUnit.Point)
Dim hPt As Double = LengthUnitConverter.Convert(7, LengthUnit.Centimeter, LengthUnit.Point)
Dim pict As New Picture(dc, Layout.Inline(New Size(wPt, hPt)), "..\..\..\image1.jpg")
par.Inlines.Add(pict)
footer.Blocks.Add(par)
s.HeadersFooters.Add(footer)
dc.Save(documentPath)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
End Sub
End Module
See Also