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

Section

Section:

Properties handle for a section within a document body.

Section is a properties handle for a contiguous range of body content. It exposes:

Sections are emergent: a section’s range is delimited by paragraphs carrying a section break (Paragraph.hasSectionBreak). The trailing section has no closing break, so Body.sections always returns N + 1 entries where N is the number of paragraphs carrying a break.

Block-level content (paragraphs and tables) is owned by Body, not by Section. To read or mutate block-level content, get the container via Body.content and call BlockLevelContainer.blocklevels, BlockLevelContainer.addParagraph, BlockLevelContainer.addTable, or BlockLevelContainer.removeElement. To navigate from a block to the section it belongs to, use Paragraph.findSection or Table.findSection.

Configure a section’s page setup and headers/footers:

const section = document.body().sections()[0];
const size = section.pageSetup().pageSize();
console.log(`Page size: ${size.width} x ${size.height}`);
const headers = section.headersAndFooters().headers();
const defaultHeader = headers.default();
if (defaultHeader) {
defaultHeader.addParagraph().asTextView().setText('Document Title');
}

Find the section a block belongs to:

const block = body.content().blocklevels()[5];
const section = block.findSection();
section?.pageSetup().setPageMargins({ top: 36, bottom: 36, left: 72, right: 72 });

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');
}