Skip to content
Document Authoring DA  API Docs v1.10.0
npmGitHub

HeadersAndFooters

HeadersAndFooters:

Provides access to both headers and footers for a section.

HeadersAndFooters is a container that provides access to both the headers and footers for a section. It’s obtained via Section.headersAndFooters and acts as a gateway to the HeadersFooters collections for headers and footers separately.

Headers appear at the top of pages, footers at the bottom. Both can have different content for:

  • Default pages (typically odd pages)
  • First page (often different for title pages)
  • Even pages (for two-sided printing)

Access headers and footers:

const hf = section.headersAndFooters();
const headers = hf.headers();
const footers = hf.footers();
// Work with default header
const defaultHeader = headers.default();
if (defaultHeader) {
const para = defaultHeader.addParagraph();
para.asTextView().setText('Document Title');
}
// Work with default footer
const defaultFooter = footers.default();
if (defaultFooter) {
const para = defaultFooter.addParagraph();
para.asTextView().setText('Page ');
}

Replace text in all headers and footers:

const hf = section.headersAndFooters();
// Replace across all headers and footers (default, first, even)
const count = hf.replaceText(/Company Name/g, 'Acme Corporation');
console.log(`Updated ${count} occurrences in headers/footers`);

Add content to different header/footer types:

const hf = section.headersAndFooters();
// Set up first page header (title page)
const firstHeader = hf.headers().first();
if (firstHeader) {
const para = firstHeader.addParagraph();
para.asTextView().setText('Title Page Header');
}
// Set up default header (for subsequent pages)
const defaultHeader = hf.headers().default();
if (defaultHeader) {
const para = defaultHeader.addParagraph();
para.asTextView().setText('Chapter 1');
}

replaceText: ReplaceTextSignature

Replaces all occurrences of a pattern in all headers and footers.

Convenience method that searches and replaces text across all headers and footers for this section, including default, first page, and even page variants.

See ReplaceTextSignature for detailed parameter and usage information.

const count = headersAndFooters.replaceText('Draft', 'Final');
console.log(`Updated ${count} occurrences`);
headersAndFooters.replaceText(/\(c\)/gi, {
text: '©',
formatting: { fontSize: 10 }
});

headers(): HeadersFooters

Gets the headers collection for this section.

HeadersFooters

A HeadersFooters object providing access to header variants

Returns the headers collection, which provides access to default, first page, and even page headers. Headers appear at the top of pages.

const headers = headersAndFooters.headers();
const defaultHeader = headers.default();
const firstPageHeader = headers.first();
const evenPageHeader = headers.even();

footers(): HeadersFooters

Gets the footers collection for this section.

HeadersFooters

A HeadersFooters object providing access to footer variants

Returns the footers collection, which provides access to default, first page, and even page footers. Footers appear at the bottom of pages.

const footers = headersAndFooters.footers();
const defaultFooter = footers.default();
const firstPageFooter = footers.first();
const evenPageFooter = footers.even();