Skip to main content

Sections in Rich Text Documents

  • 4 minutes to read

Sections in the User Interface

You can insert section and page breaks and set the page layout options using the Page Layout ribbon tab. Refer to the How to: Create the RichEditControl with a Ribbon UI topic for information on how to add a Ribbon UI to the RichEditControl.

Use the RichEditBehaviorOptions.PageBreakInsertMode property to specify whether a page break is inserted next to the specified position or in the new line.

XtraRichEdit_PageLayout_UI_Ribbon

The RichEditControl ships with the Page Setup Dialog. This dialog allows end users to define a page’s format options for an entire document or a specific section.

Tip

Set the DocumentCapabilitiesOptions.Sections property to Hidden or Disabled to restrict end users from managing document sections.

Divide a Document into Sections

The Document.Sections property provides access to the document’s section collection. Use the following methods to insert a section in code:

Document.InsertSection
Inserts a new section at the specified document position.
Document.AppendSection
Appends a new section.

Specify the Section.StartType property to define the section break’s type. The RichEditControl supports the following section breaks:

Next Page
Starts the new section on the following page.
Continuous
Starts the new section on the same page.
Even Page
Starts a new section on the next even-numbered page.
Odd Page
Starts a new section on the next odd-numbered page.
Column
Starts a new section on the next column on the page.

Define Page Formatting Options

Each section has page formatting options. You can use the SectionPage class properties to specify the page’s paper type, orientation, margins, etc. Use the Section.Page property to access the SectionPage object.

The code sample below specifies the first section’s page formatting options: sets the portrait orientation and the A3 Extra paper size.

Section firstSection =  richEditControl1.Document.Sections[0];
firstSection.Page.Landscape = false;
firstSection.Page.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.A3Extra;

Line Numbering

Set the SectionLineNumbering.CountBy property to a non-zero value to enable line numbering. Refer to the following topic for more information: Line Numbering.

Line numbers in the Print Layout View are displayed automatically. Use the RichEditView.AllowDisplayLineNumbers property to show line numbers in Simple and Draft views.

Columns

Call the SectionColumns.CreateUniformColumns method to create a multi-column layout. Refer to the following topic for more information: How to: Create a Three-Column Layout with Uniform Columns.

Page Numbering

Each document section has its own page numbering settings (page number format, initial number, etc.). Use the Section.PageNumbering property to access the SectionPageNumbering class properties and specify the section’s page numbering options. To reset the numbering options, set the SectionPageNumbering.ContinueNumbering property to false before you apply new options. The PAGE field is the document’s page number. To apply new settings to existing page numbers, call the Document.UpdateAllFields() method to update all fields.

The code sample below specifies the initial number and the NumberingFormat.CardinalText numbering format.

XtraRichEdit_PageNumbering

Section section = richEditControl1.Document.Sections[0];
section.PageNumbering.ContinueNumbering = false;
section.PageNumbering.FirstPageNumber = 3;
section.PageNumbering.NumberingFormat = NumberingFormat.CardinalText;

if (section.HasHeader(HeaderFooterType.Primary))
{
    var footer = section.BeginUpdateFooter();
    footer.Fields.Create(footer.Range.End, "PAGE");
    section.EndUpdateFooter(footer);
}

richEditControl1.Document.UpdateAllFields();

Headers and Footers

Headers and footers in the document belong to a particular section. You can use the Section.BeginUpdateHeader - Section.EndUpdateHeader and the Section.BeginUpdateFooter - Section.EndUpdateFooter method pairs to edit header or footer content. Refer to the following topic for more information: Headers and Footers.

Footnote and Endnote Options

You can specify footnote and endnote options for each document section. The Section.FootnoteOptions property provides access to the footnote options; the Section.EndnoteOptions property retrieves the endnote options. Refer to the following topic for more information: Footnotes and Endnotes.

Section Protection

You can protect/unprotect certain sections in your document.

In the UI, do the following to protect/unprotect sections:

  1. Click Protect Document on the Review ribbon tab to open the Document Protection dialog.
  2. In the invoked dialog, set the document protection type to Filling in Forms (allows users to fill in forms and form fields).
  3. Select sections to be protected. When the section checkbox is selected, you can modify text only in form fields in this section.

    Rich Text Editor - Document Protection

To protect sections in code, set the section’s ProtectedForForms property to true. When a section is protected, you can only modify text in form fields. The following code snippet loads a file with two sections, protects the first section in the document, and unprotects the second section in the document:

//...
richEditControl.LoadDocument(@"C:\DocumentWithTwoSections.docx", DocumentFormat.OpenXml);
richEditControl.Document.Sections[0].ProtectedForForms = true;
richEditControl.Document.Sections[1].ProtectedForForms = false;
richEditControl.Document.Protect("", DocumentProtectionType.FillInForms);
//...
See Also