PageMargins
PageMargins:
Defines the margin dimensions for a page.
Remarks
Section titled “Remarks”PageMargins specifies the whitespace between the page edges and the content area for
a section. left, right, top, and bottom describe the body content area;
header and footer describe how far the header and footer are placed from the top
and bottom page edges respectively, independent of the body margins. All values are
measured in points (1 point = 1/72 inch).
Page margins are configured through PageSetup.setPageMargins and retrieved
via PageSetup.pageMargins. Each section can have its own margin settings,
allowing different parts of a document to have different layouts.
Common margin values:
- Normal margins (US Letter): 72 points (1 inch) on all sides
- Narrow margins: 36 points (0.5 inch) on all sides
- Wide margins: 144 points (2 inches) on all sides
Examples
Section titled “Examples”Get current margins:
const pageSetup = section.pageSetup();const margins = pageSetup.pageMargins();
console.log(`Top: ${margins.top}pt`);console.log(`Bottom: ${margins.bottom}pt`);console.log(`Left: ${margins.left}pt`);console.log(`Right: ${margins.right}pt`);Set standard 1-inch margins:
const pageSetup = section.pageSetup();pageSetup.setPageMargins({ top: 72, bottom: 72, left: 72, right: 72});Set narrow margins (0.5 inch):
pageSetup.setPageMargins({ top: 36, bottom: 36, left: 36, right: 36});Properties
Section titled “Properties”left:
number
The left margin width in points.
Remarks
Section titled “Remarks”Distance from the left edge of the page to the start of the content area. Measured in points (1 point = 1/72 inch).
right:
number
The right margin width in points.
Remarks
Section titled “Remarks”Distance from the right edge of the page to the end of the content area. Measured in points (1 point = 1/72 inch).
top:
number
The top margin height in points.
Remarks
Section titled “Remarks”Distance from the top edge of the page to the start of the content area. Measured in points (1 point = 1/72 inch).
bottom
Section titled “bottom”bottom:
number
The bottom margin height in points.
Remarks
Section titled “Remarks”Distance from the bottom edge of the page to the end of the content area. Measured in points (1 point = 1/72 inch).
header
Section titled “header”header:
number
The distance from the top edge of the page to the top edge of the header.
Remarks
Section titled “Remarks”Distance from the top edge of the page to the header area. Measured in points (1 point = 1/72 inch).
footer
Section titled “footer”footer:
number
The distance from the bottom edge of the page to the bottom edge of the footer.
Remarks
Section titled “Remarks”Distance from the bottom edge of the page to the footer area. Measured in points (1 point = 1/72 inch).