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

Section

Section:

Represents a section within a document body.

Section is a major organizational unit within a document. Each section can have its own:

Most documents have a single section with consistent page layout and headers/footers throughout. Multi-section documents are used when you need different page layouts (e.g., landscape vs portrait) or different headers/footers (e.g., different headers per chapter) in different parts of the document.

Sections are obtained from Body.sections and can be added with Body.addSection.

Access and work with section components:

const sections = document.body().sections();
const section = sections[0];
// Access page setup
const pageSetup = section.pageSetup();
const size = pageSetup.pageSize();
console.log(`Page size: ${size.width} x ${size.height}`);
// Access content
const content = section.content();
const blockLevels = content.blocklevels();
console.log(`Section has ${blockLevels.length} elements`);
// Access headers/footers
const hf = section.headersAndFooters();
const headers = hf.headers();

Add content to a section:

const section = document.body().sections()[0];
const content = section.content();
// Add a paragraph
const paragraph = content.addParagraph();
paragraph.asTextView().setText('This is a new paragraph.');
// Add a table
const table = content.addTable();
const row = table.addRow();
const cell = row.addCell();

Replace text within a section:

const section = document.body().sections()[0];
// Replace text in this section only (content + headers/footers)
const count = section.replaceText(/TODO/g, {
text: 'DONE',
formatting: { highlight: '#ffff00' }
});
console.log(`Replaced ${count} occurrences in this section`);

replaceText: ReplaceTextSignature

Replaces all occurrences of a pattern within this section.

Convenience method that searches and replaces text across all content in this section, including the main content, headers, and footers. This is scoped to just this section, unlike Body.replaceText or Document.replaceText which operate across all sections.

See ReplaceTextSignature for detailed parameter and usage information.

// Replace only in this section
const count = section.replaceText(/old/g, 'new');
console.log(`Replaced ${count} occurrences in section`);
section.replaceText(/DRAFT/gi, {
text: 'FINAL',
formatting: { color: '#00aa00', bold: true }
});

pageSetup(): PageSetup

Gets the page setup configuration for this section.

PageSetup

The PageSetup for this section

Returns the page setup object that controls the physical page properties for this section, including page size (width/height) and margins. Each section can have different page setup settings.

const pageSetup = section.pageSetup();
const size = pageSetup.pageSize();
const margins = pageSetup.pageMargins();
console.log(`Page: ${size.width}x${size.height}`);
console.log(`Margins: T:${margins.top} B:${margins.bottom}`);

headersAndFooters(): HeadersAndFooters

Gets the headers and footers configuration for this section.

HeadersAndFooters

The HeadersAndFooters container for this section

Returns an object that provides access to headers and footers for this section. Headers and footers can have different content for the first page, even pages, and default (odd) pages.

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

content(): BlockLevelContainer

Gets the main content container for this section.

BlockLevelContainer

The BlockLevelContainer containing the section’s content

Returns a container that holds all block-level elements (paragraphs and tables) for this section. This is where the main document content resides, separate from headers and footers.

const content = section.content();
const blockLevels = content.blocklevels();
// Iterate through paragraphs and tables
for (const bl of blockLevels) {
if (bl.type === 'paragraph') {
const text = bl.asTextView().getPlainText();
console.log('Paragraph:', text);
} else if (bl.type === 'table') {
console.log('Table with', bl.rows().length, 'rows');
}
}