In This Topic
In NOV Rich Text Editor for .NET, each text document consists of one or more sections. Each section provides information about a page or a group of pages that contain the contents of the section. This information includes the page size, page margins and padding, page border, header and footer, etc. In NOV Rich Text Editor a section is represented by an instance of the NSection class.
Creating a Section
You create a section by creating an instance of the
NSection class. The following example creates two sections, where the second section starts on a new page:
Adding Sections |
Copy Code
|
NSection firstSection = new NSection();
firstSection.Blocks.Add(new NParagraph("First Page"));
m_RichText.Content.Sections.Add(firstSection);
NSection secondSection = new NSection();
secondSection.BreakType = ENSectionBreakType.NextPage;
secondSection.Blocks.Add(new NParagraph("Second Page"));
m_RichText.Content.Sections.Add(secondSection);
|
Page Size and Orientation
Page Size
Each section can use a different page size. This property is regarded when the control is rendering to paged media - for example when exporting to PDF or when printing. The following code snippet shows how to create a section with page size “Letter”:
Setting Page Size |
Copy Code
|
NSection section = new NSection();
section.PageSize = new NPageSize(ENPaperKind.Letter);
section.Blocks.Add(new NParagraph("First Page"));
m_RichText.Content.Sections.Add(section);
|
Page Orientation
The PageOrientation property allows you to specify whether pages generated by the section are in Portrait or Landscape mode;
Setting Page Orientation |
Copy Code
|
section.PageOrientation = ENPageOrientation.Landscape;
|
Adding Headers and Footers
Each section specified a set of headers and footers that must be applied to the pages generated by that section. You can specify different headers and footers depending on whether the page is the first page generated by a section and whether the page is even or odd in the document.
The following table shows the properties that specify the headers and footers of a section:
Property |
Description |
Header, Footer |
Specify the header and footer for all pages. For the first page generated in a section, these properties have an effect when DifferentFirstHeaderAndFooter property is set to false. For the rest of the pages generated by the section, this property has effect when DifferentLeftRightHeadersAndFooters property is set to false. |
HeaderFirst, FooterFirst |
Specify the first header/footer when DifferentFirstHeaderAndFooter property is set to true. |
HeaderLeft, HeaderRight, FooterLeft, FooterRight |
Specify the left/right header and footer when DifferentLeftRightHeadersAndFooters property is set to true. |
The following code snippet shows how to configure a section with different first, left, and right header and footer:
Setting Page Orientation |
Copy Code
|
NSection section = new NSection();
// configure headers and footers
section.DifferentFirstHeaderAndFooter = true;
section.DifferentLeftRightHeadersAndFooters = true;
section.HeaderFirst = new NHeaderFooter("Header on First Page");
section.HeaderLeft = new NHeaderFooter("Header on Left Page");
section.HeaderRight = new NHeaderFooter("Header on Right Page");
section.FooterFirst = new NHeaderFooter("Footer on First Page");
section.FooterLeft = new NHeaderFooter("Footer on Left Page");
section.FooterRight = new NHeaderFooter("Footer on Right Page");
// create a section with three pages
NParagraph p1 = new NParagraph("First Page");
p1.PageBreakAfter = true;
section.Blocks.Add(p1);
NParagraph p2 = new NParagraph("Second Page");
p2.PageBreakAfter = true;
section.Blocks.Add(p2);
NParagraph p3 = new NParagraph("Third Page");
section.Blocks.Add(p3);
m_RichText.Content.Sections.Add(section);
|
Headers and footers automatically update fields that contain paging information such as Page Number, Page Count, and Section Page Number.
Header and Footer Offset
The HeaderOffset and FooterOffset properties control the offset of the header and footer from the top and bottom edge of the page respectively. The following code snippet shows how to increase the distance of the header from the top of the page:
Setting Page Orientation |
Copy Code
|
section.Header = new NHeaderFooter("Header offset at 100dip");
section.HeaderOffset = 100;
|
Page Appearance
Each page generated by the section follows the block model described earlier – e.g. it has margins, padding, border, and background. Those properties are controlled from the PageMargins, PageBorderThickness, PagePadding, PageFill, and PageBorder properties of the section. The following code snippet shows how to alter the page margins and border:
Page Appearance |
Copy Code
|
section.PageMargins = new NMargins(70);
section.PageBorderThickness = new NMargins(3);
section.PageBorder = NBorder.CreateFilledBorder(NColor.Red);
|
Page Border Around Header / Footer
When the page is generated you have the option to specify whether the page border surrounds the header or footer elements on that page. This is achieved from the PageBorderSurroundsHeader and PageBorderSurroundsFooter properties:
Page Border Around Header / Footer |
Copy Code
|
section.PageBorderSurroundsHeader = false;
section.PageBorderThickness = false;
|
By default, the page border surrounds the page header and footer.
Section Columns
Sections can split the pages they occupy into one or more columns. This feature is controlled from the Columns property of the section specifying the number of columns present in the section. Columns are commonly used when you want to achieve a newspaper-like layout. The following code snippet shows how to modify the Columns property of the section:
Section Columns |
Copy Code
|
section.ColumnCount = 2; // instruct the section to generate two columns
|
When you create a section that contains more than one column (which is the default) you can also control the spacing between adjacent columns through the ColumnSpacing property of the section as well as the appearance of the separator line drawn between adjacent columns:
Section Columns |
Copy Code
|
section.ColumnCount = 2;
section.ColumnSpacing = 40;
section.ColumnSeparatorStroke = new NStroke(2, NColor.Black);
|
Break Type
The section object has a property called BreakType that allows you to control how the section is positioned when the control layout is set to print. The following table lists the available options:
ENSectionBreakType |
Description |
Continuous |
The section is continuous. The section content continues in the page/column generated by the previous section. |
ColumnBreak |
The section breaks the current column and starts on a new column. |
NextPage |
The section always starts on a new page. |
EvenPage |
The section always starts on an even page. |
OddPage |
The section always starts on an odd page. |
Setting Break Type |
Copy Code
|
section.BreakType = ENSectionBreakType.NextPage; // instruct the section to generate two columns
|
When you use Continuous or ColumnBreak break types and the previous section column count differs from the section column count the two sections will share the same page. If the previous section page size is different then Continuous and ColumnBreak break types behave like NextPage - e.g. the content of the section starts from the next page.
See Also