Class PageSetup
- Namespace
- DocToolkit
- Assembly
- DocToolkit.Primitives.dll
The paper a generated document is laid out on: size, orientation and margins, all in points.
Immutable and built by factories — A4, Letter or
Custom(double, double) — then copied by Landscape() and WithMargins. The same
shape as DocxBlock, PptxSlide, XlsxSheet and
XlsxFormula, so the five read as a set.
Points throughout, because DocxBlock.Image already takes
widthPoints/heightPoints, and a library with two length units is a library that
will eventually mix them up. OOXML stores these as twentieths of a point; that conversion lives
in SectionPropertiesFactory and never reaches a caller.
Only two presets. A3, Legal and the rest are one line each and can be added when somebody asks; Custom(double, double) covers them meanwhile.
There is no Portrait(). It has no defensible answer for a square custom page —
"the longer side vertical" is undefined when there is no longer side. Both presets are already
portrait and this type is immutable, so start from the preset again.
public sealed class PageSetup
- Inheritance
-
PageSetup
- Inherited Members
Properties
A4
ISO A4 portrait — 210 × 297 mm — with one-inch margins. The default for every producer.
The one-decimal values are not sloppiness: 210 mm is 595.2756 pt, and 595.3 × 20 is the 11906 twentieths Word itself writes for A4. Rounding to 595 would write 11900 and render a page 0.3 pt narrower than every other tool's A4.
public static PageSetup A4 { get; }
Property Value
BottomPoints
The bottom margin, in points.
public double BottomPoints { get; }
Property Value
FirstPageFooter
The footer on page one when HasDistinctFirstPage, or null for none.
public DocxHeader? FirstPageFooter { get; }
Property Value
FirstPageHeader
The header on page one when HasDistinctFirstPage, or null for none.
public DocxHeader? FirstPageHeader { get; }
Property Value
Footer
The footer on every page, or null for none.
public DocxHeader? Footer { get; }
Property Value
HasDistinctFirstPage
Whether page one is treated differently — set by calling WithFirstPage(DocxHeader?, DocxHeader?), and
emitted as w:titlePg.
public bool HasDistinctFirstPage { get; }
Property Value
Header
The header on every page, or null for none.
public DocxHeader? Header { get; }
Property Value
HeightPoints
The page height, in points.
public double HeightPoints { get; }
Property Value
LeftPoints
The left margin, in points.
public double LeftPoints { get; }
Property Value
Letter
US Letter portrait — 8.5 × 11 in — with one-inch margins.
public static PageSetup Letter { get; }
Property Value
RightPoints
The right margin, in points.
public double RightPoints { get; }
Property Value
TopPoints
The top margin, in points.
public double TopPoints { get; }
Property Value
WidthPoints
The page width, in points.
public double WidthPoints { get; }
Property Value
Methods
Custom(double, double)
A page of the given size, in points, with one-inch margins.
public static PageSetup Custom(double widthPoints, double heightPoints)
Parameters
widthPointsdoubleThe page width. Must be positive.
heightPointsdoubleThe page height. Must be positive.
Returns
Remarks
The content area is deliberately NOT validated here, unlike
WithMargins(double, double, double, double) and Landscape(). A page smaller than the one-inch
defaults — Custom(100, 400) — is a legitimate starting point for
Custom(100, 400).WithMargins(0, 60, 0, 40), and guarding construction would make a
small page impossible to build at all rather than merely awkward. Tried 2026-08-15 and
reverted: it broke three tests that construct exactly that shape.
The cost is real and is the caller's to avoid: a Custom page too small for the
default margins, used without WithMargins(double, double, double, double), produces a document Word renders
blank. Nothing refuses it, because the only place that could is the conversion boundary,
and moving the check there would change when a shipped API throws.
Exceptions
- ArgumentOutOfRangeException
Either dimension is not a positive, finite number no larger than
int.MaxValue / 20.
Landscape()
A copy with the width and height swapped, keeping the margins as they are.
This swaps rather than normalises, so calling it twice returns to where you started.
public PageSetup Landscape()
Returns
Exceptions
- ArgumentException
The swap leaves no content area — the margins were valid against the old dimensions and are not against the new ones.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
WithFirstPage(DocxHeader?, DocxHeader?)
A copy whose first page is treated separately.
public PageSetup WithFirstPage(DocxHeader? header, DocxHeader? footer)
Parameters
headerDocxHeaderPage one's header, or null for none.
footerDocxHeaderPage one's footer, or null for none.
Returns
Remarks
Calling this is the switch: it emits w:titlePg, and then null means blank on page
one rather than "use the ordinary one". That mirrors the format — an absent first-page
reference produces no header, and there is no inheritance to fall back on — and it makes the
common case sayable: a title page with nothing running across it.
Not calling this at all leaves page one looking like every other page.
WithFooter(DocxHeader)
A copy carrying footer on every page.
public PageSetup WithFooter(DocxHeader footer)
Parameters
footerDocxHeaderThe footer content.
Returns
Exceptions
- ArgumentNullException
footeris null.
WithHeader(DocxHeader)
A copy carrying header on every page.
public PageSetup WithHeader(DocxHeader header)
Parameters
headerDocxHeaderThe header content.
Returns
Exceptions
- ArgumentNullException
headeris null.
WithMargins(double)
A copy with all four margins set to points.
public PageSetup WithMargins(double points)
Parameters
pointsdoubleThe margin to apply on all four sides.
Returns
Exceptions
- ArgumentOutOfRangeException
pointsis negative, NaN or too large.- ArgumentException
The margins leave no content area.
WithMargins(double, double, double, double)
A copy with the four margins set individually, clockwise from the top — the order CSS uses.
public PageSetup WithMargins(double topPoints, double rightPoints, double bottomPoints, double leftPoints)
Parameters
topPointsdoubleThe top margin.
rightPointsdoubleThe right margin.
bottomPointsdoubleThe bottom margin.
leftPointsdoubleThe left margin.
Returns
Exceptions
- ArgumentOutOfRangeException
A margin is negative, NaN or too large.
- ArgumentException
The horizontal or vertical margins together are at least the page's width or height. Such a document opens and renders as a blank page rather than failing, so it is refused here.