Click or drag to resize

HeaderFooter(DocumentCore, HeaderFooterType) Constructor

Initializes a new instance of the HeaderFooter class.

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.11.20
Syntax
public HeaderFooter(
	DocumentCore document,
	HeaderFooterType headerFooterType
)

Parameters

document  DocumentCore
The owner document.
headerFooterType  HeaderFooterType
Type of the header / footer.
Example

See Developer Guide: How to add a header and footer in the document

How to add a header and footer into PDF document using C#
using System.IO;
using SautinSoft.Document;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Get your free 100-day key here:   
            // https://sautinsoft.com/start-for-free/

            AddHeaderFooter();
        }

        /// <summary>
        /// How to add a header and footer into PDF document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/add-header-and-footer-in-pdf-net-csharp-vb.php
        /// </remarks>
        static void AddHeaderFooter()
        {
            string inpFile = @"..\..\..\shrek.pdf";
            string outFile = "Shrek with header and footer.pdf";
            DocumentCore dc = DocumentCore.Load(inpFile);

            // Create new header with formatted text.
            HeaderFooter header = new HeaderFooter(dc, HeaderFooterType.HeaderDefault);
            header.Content.Start.Insert("Shrek and Donkey", new CharacterFormat() { Size = 14.0, FontColor = Color.Brown });
            foreach (Section s in dc.Sections)
            {
                s.HeadersFooters.Add(header.Clone(true));
            }

            // Create new footer with formatted text.
            HeaderFooter footer = new HeaderFooter(dc, HeaderFooterType.FooterDefault);
            footer.Content.Start.Insert("Fiona.", new CharacterFormat() { Size = 14.0, FontColor = Color.Blue });
            foreach (Section s in dc.Sections)
            {
                s.HeadersFooters.Add(footer.Clone(true));
            }

            dc.Save(outFile);

            // Open the PDF documents for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(inpFile) { UseShellExecute = true });
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
        }
    }
}
How to add a header and footer into PDF document using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        AddHeaderFooter()
    End Sub
    ''' Get your free 100-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' How to add a header and footer into PDF document.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/add-header-and-footer-in-pdf-net-csharp-vb.php
    ''' </remarks>
    Sub AddHeaderFooter()
        Dim inpFile As String = "..\..\..\shrek.pdf"
        Dim outFile As String = "Shrek with header and footer.pdf"
        Dim dc As DocumentCore = DocumentCore.Load(inpFile)

        ' Create new header with formatted text.
        Dim header As New HeaderFooter(dc, HeaderFooterType.HeaderDefault)
        header.Content.Start.Insert("Shrek and Donkey", New CharacterFormat() With {
                .Size = 14.0,
                .FontColor = Color.Brown
            })
        For Each s As Section In dc.Sections
            s.HeadersFooters.Add(header.Clone(True))
        Next s

        ' Create new footer with formatted text.
        Dim footer As New HeaderFooter(dc, HeaderFooterType.FooterDefault)
        footer.Content.Start.Insert("Fiona.", New CharacterFormat() With {
                .Size = 14.0,
                .FontColor = Color.Blue
            })
        For Each s As Section In dc.Sections
            s.HeadersFooters.Add(footer.Clone(True))
        Next s

        dc.Save(outFile)

        ' Open the PDF documents for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(inpFile) With {.UseShellExecute = True})
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
    End Sub
End Module
See Also