Background Color:
 
Background Pattern:
Reset
Search
Home Recent Changes Show All Pages

PageNumber and PageOf

Not Rated Yet

The PageNumber and PageOf components display the actual page numbers within a document, rather than hard coding the value. PageNumber is the number of the current page, and PageOf is the number of the page where another component is placed.

 

Article Contents

 

Current Page Number

 

The simplest way to display the current page number in a document is to use the page number component

<?xml version="1.0" encoding="utf-8" ?>
<pdf:Document xmlns:pdf="Scryber.Components, Scryber.Components, Version=0.8.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe"
          xmlns:style="Scryber.Styles, Scryber.Styles, Version=0.8.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe">
  <Viewer page-display="Thumbnails" page-layout="TwoPageLeft"/>
  <Styles>
    <style:Styles-Ref source="UnitStyles.psfx"/>

  </Styles>
  <Pages>
    <pdf:Section id="PageNumbers" outline-title="Simple Numbers"  >
      <Header>Pages to test the Page Numbering</Header>
      <Content>
        Content on page number <pdf:PageNumber/>
        <pdf:PageBreak/>
        Content on page number <pdf:PageNumber/>
      </Content>
      <Footer>
        <pdf:PageNumber />
      </Footer>
    </pdf:Section>
  </Pages>
</pdf:Document>

The template has explicit page numbers within the document and also a page number reference within the footer which will be repeated on all the pages. The final generated PDF includes the correct number of the page where it is used.

Because it is dynamic, then no matter where the component is placed, or if pages are inserted before it, or the generated content overflows, it will always render the actual page number of the current page where the output

 

 

 

Getting the page number of another component

 

What if we need to get the page number a specific component was rendered on (or will be rendered on)?

When we want to refer to a different component and display the page number that it is rendered on we need to user the PageOf component which accepts the name or id of a component.

<?xml version="1.0" encoding="utf-8" ?>
<pdf:Document xmlns:pdf="Scryber.Components, Scryber.Components, Version=0.8.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe"
          xmlns:style="Scryber.Styles, Scryber.Styles, Version=0.8.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe">
  <Viewer page-display="Thumbnails" page-layout="TwoPageLeft"/>
  <Styles>
    <style:Styles-Ref source="UnitStyles.psfx"/>

  </Styles>
  <Pages>
    <pdf:Section id="PageNumbers" outline-title="Simple Numbers"  >
      <Header>Pages to test the Page Numbering</Header>
      <Content>
        Content on page number <pdf:PageNumber/>
        <pdf:Div id="APanel" style:width="100" style:height="100" style:margins="10pt" style:bg-color="aqua" ></pdf:Div>
        <pdf:PageBreak/>
        Content on page number <pdf:PageNumber/><pdf:Br/>
        The label is on page number <pdf:PageOf component="ALabel" /><pdf:Br/>
        And the panel is on page number <pdf:PageOf component="#APanel" />
        <pdf:PageBreak/>
        <pdf:Label name="ALabel" >This is the label on the next page.</pdf:Label>
      </Content>
      <Footer>
        <pdf:PageNumber />
      </Footer>
    </pdf:Section>
  </Pages>
</pdf:Document>

The component attribute value follows the same notation as the Link, defaulting to the name reference or using a prefix of # (hash) for referencing a component by it's ID

 

Full Size...

 

Page Number Format

The page number component supports formatting of the number output based on the @format attribute (in addition to the Page Style Item numbering options)

There are 6 different formatable values that can be included to create the whole required string.

0. Section Page Label
The {0} format item shows the current page label (Decimal, Roman, Alpha, etc.) within the current numbering section (not necessarily the same as the component section).
1. Section Page Last Label
The {1} format item shows the last page label (Decimal, Roman, Alpha, etc.) within the current numbering section
2. Document Page Number
The {2} format option shows the current page number within the whole document. Does not depend on any styling options or numbering style and will always be a positive integer value
3. Document Page Count
The {3} format option shows the last page number (count +1) within the whole document. Does not depend on any styling options or numbering style and will always be a positive integer value
4. Section Page Number
The {4} format option shows the current page number within the current numbering section as an integer value - ignoring the numbering style
5. Section Page Count
The {5} format option shows the last page number within the current numbering section as an integer value - ignoring the numbering style

So a PageNumber component can be built up easily

<PageNumber format="Page {0} of {1} ({2} of {3})" />

So on the first page in a new numbering section, that is the 3rd page of 5 in the total document

Any combination of formatting and characters can be used, and format values 2-5 will respond to any format selectors as per standard .NET number formatting.

The PageOf component also honours the numbering format when displaying the page number a component is placed on using the same options in the 'label-format' attribute.

See Also



  Rating
Rate This Page: Poor Great   |  Rate Content |
Average rating:  No Ratings Yet   
Number of Ratings : 0
  Comments
Add Comment
Björn
Page number format is a style attribute named display-format i.e:
Posted At 29-09-2015 12:07:33