Skip to content

Page setup

var document = Document.Create(doc => doc
.PageSize(PageSize.A4)
.Paragraph(p => p.Text("Hello")));

Built-in presets: A3, A4, A5, Letter, Legal. All dimensions are in points (1 pt = 1/72 inch); the exact values are listed in page sizes and colors.

For landscape orientation, flip any size:

doc.PageSize(PageSize.A4.Landscape());

Custom sizes are just a record:

doc.PageSize(new PageSize(Width: 400f, Height: 400f));

Orientation(...) sets the orientation independently of how the PageSize was written:

doc.PageSize(PageSize.A4).Orientation(PageOrientation.Landscape);

PORTRAIT makes the smaller dimension the width, LANDSCAPE the larger one - so it normalizes whatever size it is given, and PageSize(PageSize.A4.Landscape()).Orientation(PageOrientation.Portrait) yields portrait A4. Leaving it unset uses the PageSize dimensions literally. DOCX emits the native w:orient and XLSX its print orientation whenever the effective page is wider than tall, whichever way you expressed it.

Uniform margin on all sides:

doc.Margin(48f);

Or per side with Thickness(left, top, right, bottom):

doc.Margin(new Thickness(56f, 48f, 40f, 48f));

Thickness also has a two-argument form, new Thickness(horizontal, vertical), which is handy for cell padding.

The space for the page header and footer lies inside the margins. See headers and footers.

A page can carry a fill behind its content - a solid color, a linear gradient, or an image, painted edge to edge across the margins. See page backgrounds.

Everything above applies to the whole document. To give part of a document its own page size, orientation, margins, or bands - a landscape appendix, say - use sections.