Edit this page

Section

The Section class allows you to separate the content into sections. Sections are chunks of the document that can be displayed on one or several pages.

A Section can contain only Paragraph and Table elements. You are also able to customize the section layout by setting its properties.

This topic explains how to:

Create and add a Section to RadDocument

As explained in the RadDocument article, the state of the document is essential for the methods that can be used on it.

For example, you can build a RadDocument from scratch and add Sections to it in the following way:

Example 1: Add a Section to a Non-Measured Document

Section section = new Section();
this.radRichTextBox.Document.Sections.Add(section);

Splitting an already measured document into two sections at the current caret position, on the other hand, can be done by inserting a section break:

Example 2: Insert a Section Break in a Measured Document

this.radRichTextBox.InsertSectionBreak(SectionBreakType.NextPage);

The InsertSectionBreak() method accepts a parameter of type SectionBreakType. The possible values are:

  • SectionBreakType.NextPage: The default value. The next section will start on the next page.

  • SectionBreakType.OddPage: The next section will start on the next odd page.

  • SectionBreakType.EvenPage: Analogically, the next section will start on the next even page.

  • SectionBreakType.Continuous: The next section will start on the same page. This type of section break is useful for creating a formatting change, such as a different number of columns, on a page.

The distribution of the document content in sections is only visible when the document is in Paged layout mode. Furthermore, the sections and section breaks can be persisted in XAML, Docx and Rtf. If you export the document to HTML or plain text, the section breaks will be lost.

Customize a Section

The Section exposes several properties that allow you to customize the layout of the elements placed underneath it. These properties can be set directly to the section when the document is created programmatically. If the changes should be applied to the document after it has been loaded in the editor, the respective methods and commands should be used.

Here is a list of these properties:

  • PageMargin: Represents the margin towards the edges of the page when in Paged mode.

    Example 3: Change the Page Margin of a Section

        //When creating a Section programmatically
        section.PageMargin = new Padding(40, 40, 30, 30);
    
        //When the section has already been added to the document
        this.editor.ChangeSectionPageMargin(new Padding(40, 40, 30, 30));
    
  • PageOrientation: Specifies if the pages in the section should be in Portrait or Landscape mode.

    Example 4: Change the Page Orientation of a Section

        //When creating a Section programmatically
        section.PageOrientation = PageOrientation.Landscape;
    
        //When the section has already been added to the document
        this.editor.ChangeSectionPageOrientation(PageOrientation.Landscape);
    
  • Columns: Allows you to arrange the text in a Section into columns. More information on how to use this property is available in the Section Columns help article.

  • PageSize: Specifies the size of the pages in the section. The PapertTypeConverter class and the enum PaperTypes provide convenient API and predefined sizes out of the box.

    Example 5: Change the Page Size of a Section

        //When creating a Section programmatically
        section.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4);
    
        //When the section has already been added to the document
        this.editor.ChangeSectionPageSize(PaperTypeConverter.ToSize(PaperTypes.A4));
    

Add headers and footers to a Section

Each section has the following types of Headers and Footers - Default (used all through the section), First (used on the first page of the section) and Even (to be used on every even page; if set, overrides the default header/footer on all even pages of the section). Here is a how you can create a Header:

Example 6: Create a Header

Header header = new Header() { Body = radDocument, IsLinkedToPrevious = false }; 

All header/footer types are set identically.
  • In a non-measured document:

    Example 7: Assign the Header to a Section in a Non-Measured Document

        section.Headers.First = header;
    
  • In a measured document:

    Example 8: Update the Header of an Existing Document

        this.editor.UpdateHeader(this.editor.Document.Sections.First, HeaderFooterType.First, header);
    

    Setting the Footers can be done in the same way.

Adding Paragraphs to a Section

Paragraphs can be added to a section in the following ways:

  • In a non-measured document:

    Example 9: Add a Paragraph to a Section in a Non-Measured Document

        Section section = new Section();
        Paragraph paragraph = new Paragraph();
        section.Blocks.Add(paragraph);
    
  • In a measured document:

    Example 10: Add a Paragraph to a Section in a Measured Document

        this.radRichTextBox.InsertParagraph();
    

See Also

Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy