The article describes how to add and configure a section.
A section is a part of a document holding content and layout. A document may contain one or more sections. Each section may consist of several pages that will be generated automatically depending on the content. A new section starts on a new page.
You can configure settings of a section using methods of the SectionBuilder
class.
Each section has the following settings:
Settings |
Default value |
Methods for configuration |
Paper size |
|
|
Page orientation |
|
|
Page margins |
|
|
Font |
|
|
Page numbering style |
|
|
Number to start the page numbering from |
|
You can add the following content to a section (see details in the corresponding articles):
Repeating areas (headers, footers, left and right repeating areas and repeating areas by coordinates)
If you do not specify formatting settings for a section or its content items, they will have their default values defined by the default style.
You can apply a style to an entire section using the method ApplyStyle
and
set set styles for all content elements of the same type on the section level by using the methods
SetParagraphStyle
,
SetTableStyle
,
SetImageStyle
,
SetLineStyle
,
SetListStyle
.
For more on working with styles, see the article Formatting and Styles.
How to Add Section
There are several ways to add a section to a document:
Add a new section, configure it, and add content to it inside the
DocumentBuilder.AddSectionToDocument
method.
Create a new section builder using the DocumentBuilder.AddSection
method, configure it, and add content to it.
The method returns an instance of SectionBuilder
, so you can access its methods later to further configure the section.
This section will be added to the document "under the hood", without calling the SectionBuilder.BuildToDocument
method,
as soon as the document is built.
Create a new section builder using the SectionBuilder.New
method, configure it, and add content to it.
You can use different ways to add sections to the same document.
See also
Examples
Example 1. Create and configure a section with a paragraph containing text Hide
//Create a document builder:
DocumentBuilder.New()
//Add a section and section content:
.AddSection()
.SetMargins(50)
.SetOrientation(PageOrientation.Portrait)
.AddParagraph("Lorem ipsum dolor sit amet")
//Build a file:
.ToDocument().Build("Result.pdf");
The above code will generate the following:
See the document