Adding Section

Brief

The article describes how to add and configure a section.

Details

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

Letter

SectionBuilder.SetSize methods to set a custom or a predefined paper size.

Page orientation

Landscape

SetOrientation

Page margins

20f

SectionBuilder.SetMargins methods

Font

Helvetica, 11f, Black

SetStyleFont

Page numbering style

Arabic

SetNumerationStyle

Number to start the page numbering from

1

SetPageNumberStart

You can add the following content to a section (see details in the corresponding articles):

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:

  1. Add a new section, configure it, and add content to it inside the DocumentBuilder.AddSectionToDocument method.

  2. 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.

  3. 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

Creating Document

Formatting and Styles

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

back