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 : PdfFlowContainerExample
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
PdfFlowContainerPdfFlowDocument
Constructors
| Name | Description |
|---|---|
| PdfFlowDocument(PdfFlowOptions?) | Initializes a new instance of the PdfFlowDocument class. |
PdfFlowDocument(PdfFlowOptions?)
PdfFlowDocument.csInitializes a new instance of the PdfFlowDocument class.
public PdfFlowDocument(PdfFlowOptions? options = null)Parameters
optionsPdfFlowOptions?- The options, or
nullfor the defaults.
Methods
| Name | Description |
|---|---|
| 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. |
Build()
PdfFlowDocument.csLays 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.csAdds 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
countint- The number of columns.
gapdouble- The space between the columns, in points.
contentAction<PdfFlowContainer>- The function that adds the blocks.
Returns
PdfFlowDocument The document.
Exceptions
ArgumentOutOfRangeExceptioncountis not between 1 and 16, orgapis negative.
Heading(int, string)
PdfFlowDocument.csAdds 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
Returns
PdfFlowDocument The container.
Exceptions
ArgumentOutOfRangeExceptionlevelis not between 1 and 6.
Image(PdfImage, string, double?)
PdfFlowDocument.csAdds an image (Figure), with its alternate description, which screen readers read.
public new PdfFlowDocument Image(PdfImage image, string alternateDescription, double? width = null)Parameters
imagePdfImage- The image.
alternateDescriptionstring- The description of the image.
widthdouble?- The width of the image, in points, or
nullfor 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.csAdds 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
itemsIEnumerable<Action<PdfFlowContainer>>- The functions that add the blocks of each item.
orderedbool- Whether the items are numbered (1., 2., 3.) instead of bulleted.
Returns
PdfFlowDocument The container.
List(IEnumerable<string>, bool)
PdfFlowDocument.csAdds 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
itemsIEnumerable<string>- The texts of the items.
orderedbool- Whether the items are numbered (1., 2., 3.) instead of bulleted.
Returns
PdfFlowDocument The container.
PageBreak()
PdfFlowDocument.csParagraph overloads
Paragraph(Action<PdfInlineBuilder>, PdfParagraphStyle?)
PdfFlowDocument.csAdds a paragraph (P) of runs of text, each with its style, and links.
public new PdfFlowDocument Paragraph(Action<PdfInlineBuilder> build, PdfParagraphStyle? style = null)Parameters
buildAction<PdfInlineBuilder>- The function that adds the runs.
stylePdfParagraphStyle?- The style of the paragraph, or
nullfor the default.
Returns
PdfFlowDocument The container.
Paragraph(string, PdfParagraphStyle?)
PdfFlowDocument.csAdds a paragraph (P) of text in the style of the document.
public new PdfFlowDocument Paragraph(string text, PdfParagraphStyle? style = null)Parameters
textstring- The text. A line feed breaks the line.
stylePdfParagraphStyle?- The style of the paragraph, or
nullfor the default.
Returns
PdfFlowDocument The container.
Rule(PdfColor?, double)
PdfFlowDocument.csAdds a horizontal rule, an artifact.
public new PdfFlowDocument Rule(PdfColor? color = null, double width = 0.5d)Parameters
colorPdfColor?- The color of the rule, or
nullfor gray. widthdouble- The width of the line, in points.
Returns
PdfFlowDocument The container.
Spacer(double)
PdfFlowDocument.csAdds an empty space.
public new PdfFlowDocument Spacer(double height)Table(Action<PdfFlowTableBuilder>)
PdfFlowDocument.csAdds 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
buildAction<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.csAdds 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")