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 will explain you how to:

Create and add a Section to RadDocument

As explained in the previous section, 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:


Telerik.WinForms.Documents.Model.Section section = new Telerik.WinForms.Documents.Model.Section();
this.radRichTextEditor1.Document.Sections.Add(section);

Dim section As New Telerik.WinForms.Documents.Model.Section()
Me.radRichTextEditor1.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:


this.radRichTextEditor1.InsertSectionBreak(SectionBreakType.NextPage);

Me.radRichTextEditor1.InsertSectionBreak(SectionBreakType.NextPage)

The method accept 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.

note

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.

section.PageMargin = new Telerik.WinForms.Documents.Layout.Padding(40, 40, 30, 30);

//When the section has already been added to the document
this.radRichTextEditor1.ChangeSectionPageMargin(new Telerik.WinForms.Documents.Layout.Padding(40, 40, 30, 30));

section.PageMargin = New Telerik.WinForms.Documents.Layout.Padding(40, 40, 30, 30)
'When the section has already been added to the document
Me.radRichTextEditor1.ChangeSectionPageMargin(New Telerik.WinForms.Documents.Layout.Padding(40, 40, 30, 30))

  • PageOrientation - specifies if the pages in the section should be in Portrait or Landscape mode.

//When creating a Section programmatically
section.PageOrientation = PageOrientation.Landscape;

//When the section has already been added to the document
this.radRichTextEditor1.ChangeSectionPageOrientation(PageOrientation.Landscape);

'When creating a Section programmatically
section.PageOrientation = PageOrientation.Landscape
'When the section has already been added to the document
Me.radRichTextEditor1.ChangeSectionPageOrientation(PageOrientation.Landscape)

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

//When creating a Section programmatically
section.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4);

//When the section has already been added to the document
this.radRichTextEditor1.ChangeSectionPageSize(PaperTypeConverter.ToSize(PaperTypes.A4));

'When creating a Section programmatically
section.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4)
'When the section has already been added to the document
Me.radRichTextEditor1.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 how you can create a Header:
Telerik.WinForms.Documents.Model.Header header = new Telerik.WinForms.Documents.Model.Header() { Body = radDocument, IsLinkedToPrevious = false };

Dim header As New Telerik.WinForms.Documents.Model.Header() With {.Body = radDocument, .IsLinkedToPrevious = False}

All header/footer types are set identically.

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

section.Headers.First = header

  • In a measured document:
this.radRichTextEditor1.UpdateHeader(this.radRichTextEditor1.Document.Sections.First, Telerik.WinForms.Documents.Model.HeaderFooterType.First, header);

Me.radRichTextEditor1.UpdateHeader(Me.radRichTextEditor1.Document.Sections.First, Telerik.WinForms.Documents.Model.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:


Section section1 = new Section();
Paragraph paragraph = new Paragraph();
section1.Blocks.Add(paragraph);

Dim section1 As New Section()
Dim paragraph As New Paragraph()
section1.Blocks.Add(paragraph)

In a measured document:

this.radRichTextEditor1.Insert(FormattingSymbolLayoutBox.ENTER);

Me.radRichTextEditor1.Insert(FormattingSymbolLayoutBox.ENTER)

See Also

Was this article helpful? Yes No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy