Skip to main content

PageBuilder

PageBuilder

PageBuilder configures one page and collects its elements in order. It is provided to the callback passed to DocumentBuilder.Pages(...).

Page setup​

MemberPurpose
Size(PageSize)Sets a predefined page size.
Size(double width, double height, LengthUnit? unit = null)Sets a custom page size.
Orientation(PageOrientation)Sets the page orientation.
Margins(double all, ...)Sets equal margins.
Margins(double horizontal, double vertical, ...)Sets horizontal and vertical margins.
Margins(double top, double right, double bottom, double left, ...)Sets each margin independently.
Padding(...), Border(...), Background(...)Configures page styling and background.
Style(string)Adds page-level style text.
Header(Action<HeaderFooterBuilder>), Footer(Action<HeaderFooterBuilder>)Configures header and footer bands.

Lengths use the document's default unit unless the method accepts an explicit LengthUnit.

Add page elements​

The builder includes methods for text, images, tables, rectangles, columns, ordered and unordered lists, barcodes, and imported PDF pages. Many accept a callback that configures the corresponding element builder.

DocumentBuilder.Create()
.DefaultUnit(LengthUnit.Point)
.Pages(page => page
.Size(PageSize.A4)
.Margins(48)
.Header(header => header.Center("Quarterly report"))
.Text("Summary")
.Spacing(12)
.Text("Revenue increased this quarter."))
.Save("report.pdf");

Other page operations include Spacing(...), PageBreak(), Bookmark(...), Watermark(...), and PdfTemplate(...). PdfPage(...) sets an imported PDF page as a page background.

For working scenarios, see headers and footers, columns, tables, and adding content to an existing PDF.