DOCX
Page Layout
Configure page size, orientation, margins, columns, and section breaks
Control document layout through Section properties. Each document can have multiple sections with different layouts.
Page Size and Orientation
import { Document, Paragraph, SectionType } from "@office-open/docx";
const doc = new Document({
sections: [
// Portrait A4
{
properties: {
page: {
size: { width: 11906, height: 16838, orientation: "portrait" },
margins: {
top: 1440,
bottom: 1440,
left: 1440,
right: 1440,
},
},
},
children: [new Paragraph("Portrait page")],
},
// Landscape A4
{
properties: {
page: {
size: { width: 16838, height: 11906, orientation: "landscape" },
},
},
children: [new Paragraph("Landscape page")],
},
],
});
Page Margins
properties: {
page: {
margins: {
top: 1440, // 1 inch (in twips)
bottom: 1440,
left: 1440,
right: 1440,
gutter: 0, // Binding gutter
header: 720, // Header distance from top
footer: 720, // Footer distance from bottom
},
},
},
Columns
Create multi-column layouts:
properties: {
page: {
columns: {
count: 2,
space: 708, // Spacing between columns (in twips)
},
},
},
Section Breaks
Control how sections transition:
import { SectionType } from "@office-open/docx";
// Each section can specify its break type
{
properties: {
type: SectionType.CONTINUOUS, // No page break
// type: SectionType.NEXT_PAGE, // Default — new page
// type: SectionType.EVEN_PAGE, // Next even page
// type: SectionType.ODD_PAGE, // Next odd page
},
children: [...],
},
Page Borders
properties: {
page: {
borders: {
top: { style: "single", size: 6, color: "000000", space: 24 },
bottom: { style: "single", size: 6, color: "000000", space: 24 },
left: { style: "single", size: 6, color: "000000", space: 24 },
right: { style: "single", size: 6, color: "000000", space: 24 },
},
},
},