Hi every body ....
I use RadRichTextBox in the following manner: first page is used (by the user) as a cover letter so that it is not included within the total count of pages. Footer of every page except first page should display page number x from y, where x is the current page number (after the first page), and y is the total number of pages minus one (the first page).
I could achieve the first value of the formatted footer using CodeBasedField, but unfortunately I couldn't modify the value returned by NumPagesField.
My question is how to modify value returned by NumPagesField so that I can display total number of pages minus one. Below there is an attachment of an image to show my requirement.
The following is my code snippet used in creating the custom footer:
Public
Function
FirstTemplate()
As
RadDocument
Dim
section
As
New
Section()
section.HasDifferentFirstPageHeaderFooter =
True
section.Footers.[
Default
] =
New
Footer
With
{.Body = ReportFooter()}
End
Function
Private
Function
ReportFooter()
As
RadDocument
Dim
footerDoc
As
New
RadDocument
Dim
footerSection
As
New
Section
Dim
footerParagraph
As
New
Paragraph
Dim
footerDocumentEditor
As
New
RadDocumentEditor(footerDoc)
footerParagraph.TextAlignment = RadTextAlignment.Center
footerDoc.Sections.Add(footerSection)
footerSection.Blocks.Add(footerParagraph)
footerDocumentEditor.InsertField(
New
FormattedPageNumber, FieldDisplayMode.Result)
footerDocumentEditor.InsertField(
New
NumPagesField, FieldDisplayMode.Result)
'??? how to return total number of pages -1
Return
footerDoc
End
Function
Public
Class
FormattedPageNumber
Inherits
CodeBasedField
Public
Shared
ReadOnly
FieldType
As
String
=
"FormattedPageNUM"
Shared
Sub
New
()
CodeBasedFieldFactory.RegisterFieldType(FormattedPageNumber.FieldType,
Function
()
Return
New
FormattedPageNumber()
End
Function
)
End
Sub
Public
Overrides
ReadOnly
Property
FieldTypeName()
As
String
Get
Return
FormattedPageNumber.FieldType
End
Get
End
Property
Protected
Overrides
Function
GetResultFragment()
As
DocumentFragment
Dim
pageNumber
As
Integer
= 0
'Dim pagesCount As Integer = 0
If
Me
.Document IsNot
Nothing
Then
Dim
position
As
New
DocumentPosition(
Me
.Document)
position.MoveToStartOfDocumentElement(
Me
.FieldStart)
Dim
sectionBox
As
SectionLayoutBox = position.GetCurrentSectionBox()
pageNumber = sectionBox.PageNumber
End
If
Dim
resultString
As
String
=
"Page "
& pageNumber - 1 &
" From "
Return
MyBase
.CreateFragmentFromText(resultString)
End
Function
Public
Overrides
Function
CreateInstance()
As
Field
Return
New
FormattedPageNumber()
End
Function
End
Class