PdfFlowDocument Class

A document laid out from blocks (headings, paragraphs, lists, images, tables): the text is broken into lines, the blocks into pages and columns, and the document is tagged, so that it is accessible (PDF/UA) when its fonts are embedded.

public sealed class PdfFlowDocument : PdfFlowContainer

Example

var flow = new PdfFlowDocument(new PdfFlowOptions
{
    Title = "Quarterly report",
    Language = "en-US",
    Footer = (page, count) => $"Page {page} of {count}",
});
flow.TableOfContents()
    .Heading(1, "Summary")
    .Paragraph(text => text
        .Text("Sales grew by ")
        .Text("12%", new PdfTextStyle { Font = PdfFont.GetStandardFont(PdfStandardFont.HelveticaBold) })
        .Text(". See ")
        .Link("the website", new Uri("https://example.com")))
    .List(["North: +8%", "South: +15%"])
    .Heading(1, "Details")
    .Table(table => table
        .Columns(2, 1)
        .HeaderRow("Region", "Sales")
        .Row("North", "1,200")
        .Row("South", "1,500"));

var document = flow.Build();
Inheritance
PdfFlowContainer PdfFlowDocument

Constructors

NameDescription
PdfFlowDocument(PdfFlowOptions?)Initializes a new instance of the PdfFlowDocument class.

PdfFlowDocument(PdfFlowOptions?)

PdfFlowDocument.cs

Initializes a new instance of the PdfFlowDocument class.

public PdfFlowDocument(PdfFlowOptions? options = null)

Parameters

options PdfFlowOptions?
The options, or null for the defaults.

Methods

NameDescription
Build()Lays out the blocks and creates the document.
Columns(int, double, Action<PdfFlowContainer>)Adds blocks laid out in columns: they fill the first column, then the next one, then the columns of the next page. The blocks that follow start below the columns.
Heading(int, string)Adds a heading (H1 to H6), in the heading font, larger for the higher levels. It is kept on the page of the block that follows it, and added to the outline and the table of contents.
Image(PdfImage, string, double?)Adds an image (Figure), with its alternate description, which screen readers read.
List(IEnumerable<Action<PdfFlowContainer>>, bool)Adds a list (L) whose items hold blocks, such as paragraphs and nested lists.
List(IEnumerable<string>, bool)Adds a list (L) of items of text: each item (LI) has a label (Lbl), a bullet or its number, and a body (LBody).
PageBreak()Starts a new page.
Paragraph(Action<PdfInlineBuilder>, PdfParagraphStyle?)Adds a paragraph (P) of runs of text, each with its style, and links.
Paragraph(string, PdfParagraphStyle?)Adds a paragraph (P) of text in the style of the document.
Rule(PdfColor?, double)Adds a horizontal rule, an artifact.
Spacer(double)Adds an empty space.
Table(Action<PdfFlowTableBuilder>)Adds a table (Table): header rows (THead, TH), rows (TBody, TR, TD) and cells that hold blocks and span columns and rows.
TableOfContents(string)Adds a table of contents (TOC): a title, then an entry (TOCI) per heading of levels 1 to 3, with its page number and a link to it.

Lays out the blocks and creates the document.

public PdfDocument Build()

Returns

PdfDocument The document. It can be changed and saved like any other.

Exceptions

ArgumentException
A character of a text has no glyph in its font.

Columns(int, double, Action<PdfFlowContainer>)

PdfFlowDocument.cs

Adds blocks laid out in columns: they fill the first column, then the next one, then the columns of the next page. The blocks that follow start below the columns.

public PdfFlowDocument Columns(int count, double gap, Action<PdfFlowContainer> content)

Parameters

count int
The number of columns.
gap double
The space between the columns, in points.
content Action<PdfFlowContainer>
The function that adds the blocks.

Returns

PdfFlowDocument The document.

Exceptions

ArgumentOutOfRangeException
count is not between 1 and 16, or gap is negative.

Heading(int, string)

PdfFlowDocument.cs

Adds a heading (H1 to H6), in the heading font, larger for the higher levels. It is kept on the page of the block that follows it, and added to the outline and the table of contents.

public new PdfFlowDocument Heading(int level, string text)

Parameters

level int
The level, from 1 to 6.
text string
The text.

Returns

PdfFlowDocument The container.

Exceptions

ArgumentOutOfRangeException
level is not between 1 and 6.

Image(PdfImage, string, double?)

PdfFlowDocument.cs

Adds an image (Figure), with its alternate description, which screen readers read.

public new PdfFlowDocument Image(PdfImage image, string alternateDescription, double? width = null)

Parameters

image PdfImage
The image.
alternateDescription string
The description of the image.
width double?
The width of the image, in points, or null for the width of the container (smaller images keep their size of 1 point per pixel). The height keeps the ratio of the image, and the image is scaled down to fit a page.

Returns

PdfFlowDocument The container.

List overloads

List(IEnumerable<Action<PdfFlowContainer>>, bool)

PdfFlowDocument.cs

Adds a list (L) whose items hold blocks, such as paragraphs and nested lists.

public new PdfFlowDocument List(IEnumerable<Action<PdfFlowContainer>> items, bool ordered = false)
Parameters
items IEnumerable<Action<PdfFlowContainer>>
The functions that add the blocks of each item.
ordered bool
Whether the items are numbered (1., 2., 3.) instead of bulleted.
Returns

PdfFlowDocument The container.

List(IEnumerable<string>, bool)

PdfFlowDocument.cs

Adds a list (L) of items of text: each item (LI) has a label (Lbl), a bullet or its number, and a body (LBody).

public new PdfFlowDocument List(IEnumerable<string> items, bool ordered = false)
Parameters
items IEnumerable<string>
The texts of the items.
ordered bool
Whether the items are numbered (1., 2., 3.) instead of bulleted.
Returns

PdfFlowDocument The container.

Starts a new page.

public PdfFlowDocument PageBreak()

Returns

PdfFlowDocument The document.

Paragraph overloads

Paragraph(Action<PdfInlineBuilder>, PdfParagraphStyle?)

PdfFlowDocument.cs

Adds a paragraph (P) of runs of text, each with its style, and links.

public new PdfFlowDocument Paragraph(Action<PdfInlineBuilder> build, PdfParagraphStyle? style = null)
Parameters
build Action<PdfInlineBuilder>
The function that adds the runs.
style PdfParagraphStyle?
The style of the paragraph, or null for the default.
Returns

PdfFlowDocument The container.

Paragraph(string, PdfParagraphStyle?)

PdfFlowDocument.cs

Adds a paragraph (P) of text in the style of the document.

public new PdfFlowDocument Paragraph(string text, PdfParagraphStyle? style = null)
Parameters
text string
The text. A line feed breaks the line.
style PdfParagraphStyle?
The style of the paragraph, or null for the default.
Returns

PdfFlowDocument The container.

Rule(PdfColor?, double)

PdfFlowDocument.cs

Adds a horizontal rule, an artifact.

public new PdfFlowDocument Rule(PdfColor? color = null, double width = 0.5d)

Parameters

color PdfColor?
The color of the rule, or null for gray.
width double
The width of the line, in points.

Returns

PdfFlowDocument The container.

Spacer(double)

PdfFlowDocument.cs

Adds an empty space.

public new PdfFlowDocument Spacer(double height)

Parameters

height double
The height of the space, in points.

Returns

PdfFlowDocument The container.

Table(Action<PdfFlowTableBuilder>)

PdfFlowDocument.cs

Adds a table (Table): header rows (THead, TH), rows (TBody, TR, TD) and cells that hold blocks and span columns and rows.

public new PdfFlowDocument Table(Action<PdfFlowTableBuilder> build)

Parameters

build Action<PdfFlowTableBuilder>
The function that adds the columns and the rows.

Returns

PdfFlowDocument The container.

Exceptions

ArgumentException
The table has no row, or its cells do not fit its columns.

TableOfContents(string)

PdfFlowDocument.cs

Adds a table of contents (TOC): a title, then an entry (TOCI) per heading of levels 1 to 3, with its page number and a link to it.

public PdfFlowDocument TableOfContents(string title = "Contents")

Parameters

title string
The title of the table of contents.

Returns

PdfFlowDocument The document.