Control Script: Page numbering
This topic explains how to write a Control Script that changes the page numbering in Print sections. Note that when you add a Control Script, it already contains a script to make the page numbering continue over all Print sections.
For information about Control Scripts in general, see Control Scripts and Control Script API. If you don't know how to write scripts, see Writing your own scripts.
How to change page numbering in a control script
A Control Script can make the page numbering continue over all Print sections or let it restart on a section. This is done by setting the restartPageNumber
field on a section
to true
or false
.
For example: merge.template.contexts.PRINT.sections['Section 2'].restartPageNumber = true;
. (Also see section and Control Script API.)
Page numbering starts with page 1 for each section. If for
a section restartPageNumber
is set to false
, that section will
start with the page number following the last page of the previous section.
Note that even if a section is not enabled (so it will not be outputted), its restartPageNumber
flag
is still taken into account for composing the page number sequences.
By default, each section has restartPageNumber
= false
when the first control script runs.
pageRef()
function. For an example, see pageref(). For a multi-page, cross-section table of contents you must use a Post Pagination Script; see Creating a Table Of Contents.
Examples
Restarting the page numbers several times
Assume that a template has four sections (of 1 page each) in the Print context and a Control Script sets the page numbering as follows:
- Section A (1 page) restartPageNumber = true
- Section B (1 page) restartPageNumber = true
- Section C (1 page) restartPageNumber = false
- Section D (1 page) restartPageNumber = true
The code would look like this:
if (merge.context.type == ContextType.PRINT) {
merge.context.sections['Section A'].restartPageNumber = true;
merge.context.sections['Section B'].restartPageNumber = true;
merge.context.sections['Section C'].restartPageNumber = false;
merge.context.sections['Section D'].restartPageNumber = true;
}
The page numbering in the output will be:
- Section A page 1
- Section B page 1
- Section C page 2
- Section D page 1
Disabled section
When a section is disabled, it will not be outputted, but its restartPageNumber
flag
will still be taken into account for composing the page number sequences. So, if the restartPageNumber
flags are set as follows:
- Section A (1 page) restartPageNumber = true
- Section B (2 pages) restartPageNumber = false
- Section C (3 pages) restartPageNumber = true, enabled = false
- Section D (4 pages) restartPageNumber = false
In code:
if (merge.context.type == ContextType.PRINT) {
merge.context.sections['Section A'].restartPageNumber = true;
merge.context.sections['Section B'].restartPageNumber = false;
merge.context.sections['Section C'].restartPageNumber = true;
merge.context.sections['Section C'].enabled = false;
merge.context.sections['Section D'].restartPageNumber = false;
}
The page numbering in the output will be:
- Section A page 1
- Section B page 2
- Section D page 1 (page numbering is restarted due to section C's restartPageNumber = true)