Nevron Open Vision Documentation
Sections

Each text document is divided into sections. The primary purpose of sections is to provide information about a page or a group of pages that contain the contents of that section. This information includes the page size, page margins and padding, page border, header and footer etc. In Nevron Text a section is represented by an instance of the NSection class.

This topic discusses the most common tasks you need to perform with sections:
Creating a Section
You create a section to the document 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 layout is print or when the control is exporting to PDF or 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 page is in Portrait or Landscape mode;

Setting Page Orientation
Copy Code
section.PageOrientation = ENPageOrientation.Landscape;
Adding Headers and Footers

Each section can have up to four different headers and footers. This arises from the common requirement to have the ability to specify different header / footer 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:

Propery Description
Header, Footer Specify the header and footer for all pages. For the first page generated in a section these properties have effect when DifferentFirstHeaderAndFooter property is 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);
Header 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 have the ability to split the pages they occupy in 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 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 trough 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 - 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 a page. If the previous section page size is different then Continuous and ColumnBreak break types behave like NextPage.

 

See Also
Send Feedback