Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

Section

Section is a BlockContainer element which can contain other block elements. You can customize its layout through its properties.

Inserting a Section

You can use the code snippet from Example 1 to create a Section element and add it to a RadFlowDocument.

Example 1: Create a section and add it to a RadFlowDocument

Section section = new Section(document); 
document.Sections.Add(section); 

You can also use the AddSection() method of the Sections collection of a document. The method creates a new Section element, adds it to the document and returns it.

Example 2: Create a section and add it to a RadFlowDocument

Section section = document.Sections.AddSection(); 

Modifying a Section

The Section exposes several properties that allow you to customize the layout of the elements placed underneath it.

  • PageMargins: Represents the margin towards the edges of the page.

    Example 3: Change margins of a section

        section.PageMargins = new Padding(10, 10, 5, 5); 
    
  • PageOrientation: Specifies whether the pages in the section should be in Portrait or in Landscape orientation. This property is used to determine the actual size of the paper to use on the printer and does not reflect document's visualization. In order to affect Section's appearance you should change PageSize and PageMargin properties, or use the Rotate method, which will change them according to the desired page orientation.

    Example 4: Change orienation of a section

        section.PageOrientation = PageOrientation.Landscape; 
    
  • PageSize: Specifies the size of the pages in the section. The width and height are in device independent pixels (1/96 inch). The PaperTypeConverter class and the PaperTypes enumeration provide convenient API and predefined sizes out of the box.

    Example 5: Change page size of a section

        section.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4); 
    
  • Headers and Footers: Each Section has three Headers and three Footers - Default (used all through the section), First (used on the first page of the section) and Even (used on even pages of the document). The three Headers are contained in the Headers class accessible through the Section.Headers property. The three Footers are contained in the Footers class accessible through the Section.Footers property. Example 6 shows how you can create default Header.

    Example 6: Create a header of a section

        Header header = section.Headers.Add(); 
        Paragraph paragraph = header.Blocks.AddParagraph(); 
        paragraph.TextAlignment = Alignment.Right; 
        paragraph.Inlines.AddRun("This is a sample header."); 
    
  • HeaderTopMargin: Gets or sets the top margin of the header. The value is in device independent pixels (1/96 inch).

  • FooterBottomMargin: Gets or sets the bottom margin of the footer. The value is in device independent pixels (1/96 inch).

More information on how to work with the different types of headers and footer can be found in the Headers and Footers article.

  • SectionType: Defines the section types:

    • NextPage: Specifies that the section starts on the next page.
    • EvenPage: Specifies that the section starts on the next even page.
    • OddPage: Specifies that the section starts on the next odd page.
    • Continuous: Specifies that the section starts on the same page.
    • NextColumn: Specifies that the section starts on the next column on the page.
  • VerticalAlignment: Defines the vertical alignment:

    • Top: Specifies the section layout is top aligned. This is the default value.
    • Bottom: Specifies the section layout is bottom aligned.
    • Center: Specifies the section layout is center aligned.
    • Justified: Specifies the section layout is justified.
  • PageNumberingSettings: Defines page numbering settings. You can modify the settings through the following properties:

    • ChapterSeparatorCharacter: Specifies the chapter separator character that shall appear between the chapter heading style index and the page number.
    • ChapterHeadingStyleIndex: Specifies the index of the chapter heading style. The possible values are from 1 to 9 inclusive (Heading1, Heading2…).
    • PageNumberFormat: Specifies the number format for the page numbering in the current section.
    • StartingPageNumber: Specifies the starting page number which shall appear on the first page of the section. The possible values are 0 or greater.
  • Properties: Gets all section properties as SectionProperties object. More info on how to use section properties can be found in Style Properties article.

Operating with a Section

Adding Elements to a Section

Section derives BlockContainerBase, inheriting Blocks property of BlockCollection type. You can add Paragraph and Table objects to that collection.

Example 7: Add elements to a section

Paragraph paragraph = section.Blocks.AddParagraph(); 
Table table = section.Blocks.AddTable(); 

Rotating a Section

The Section can be rotated in order to visualize its pages in Portrait or Landscape mode.

Example 8: Rotate a section

section.Rotate(PageOrientation.Landscape); 

See Also

In this article