addPageNumber

addPageNumber

BASIC / ADVANCED / PREMIUM

Inserts the current page number into the Word document.

Description
public addPageNumber ([string $type [, array $options]] )

This method allows you to insert automatic page numbering into your Word document.

If the page number is not added to a header or footer the user may need to press F9 in the MS Word interface to update its value to the current page.

Parameters

type

The possible values are numerical (default), alphabetical or page-of.

options

This is an array including all general paragraph wide options.

The possible keys and values of this array are:

key Type Description
pStyle string Word style to be used. Run parseStyles() method to check all available paragraph styles.
backgroundColor string Hexadecimal color value: FF0000, 000000, ...
bidi bool Sets to true for right to left languages like Hebrew or Arabic.
bold bool If true the text will be shown in bold characters.
border string Available values are:
  • none (default),
  • double
  • dashed
  • outset
  • inset
  • threeDEmboss
  • threeDEngrave
You can access to the complete list in: Border Styles.
borderBottom string Overwrites the general border type for the bottom border of the paragraph.
borderLeft string Overwrites the general border type for the left border of the paragraph.
borderTop string Overwrites the general border type for the top border of the paragraph.
borderRight string Overwrites the general border type for the right border of the paragraph.
borderColor string Hexadecimal color value: FF0000, 000000, ...
borderBottomColor string Overwrites the general border color for the bottom border of the paragraph.
borderLeftColor string Overwrites the general border color for the left border of the paragraph.
borderTopColor string Overwrites the general border color for the top border of the paragraph.
borderRightColor string Overwrites the general border color for the right border of the paragraph.
borderSpacing int Separation between border and text in points.
borderBottomSpacing int Overwrites the general border spacing for the bottom border of the paragraph.
borderLeftSpacing int Overwrites the general border spacing for the left border of the paragraph.
borderTopSpacing int Overwrites the general border spacing for the top border of the paragraph.
borderRightSpacing int Overwrites the general border spacing for the right border of the paragraph.
borderWidth int Border width in eigths of a point.
borderBottomWidth int Overwrites the general border width for the bottom border of the paragraph.
borderLeftWidth int Overwrites the general border width for the left border of the paragraph.
borderTopWidth int Overwrites the general border width for the top border of the paragraph.
borderRightWidth int Overwrites the general border width for the right border of the paragraph.
caps bool If true displays text in capital letters.
color string Hexadecimal color value: 'FF0000', '000000', ...
contextualSpacing bool If true ignores spacing above and below the paragraph whenever the neighbouring paragraphs use the same Word style (false by default).
em string Emphasis mark type: none (default), dot, circle, comma, underDot.
firstLineIndent int First line indentation in twentieths of a point (twips).
font string Font family: 'Arial', Calibri', ...
fontSize int Font size in points.
hanging int Paragraph hanging in twentieths of a point (twips).
headingLevel int The heading level if we want this paragraph to be a heading.
italic string If true displays the text in italics.
indentLeft int Left margin in points.
indentRight int Right margin in points.
keepLines bool Keeps (whenever possible) all the current paragraph lines on the same page (default value is false).
keepNext bool Keeps (whenever possible) in the same page the current paragraph with next paragraph (default value is false).
lineSpacing float
  • 1 corresponds to single line spacing
  • 2 to double line spacing and so long so forth
It admits decimal numbers.
pageBreakBefore bool If true forces a page break before the paragraph.
rtl bool Sets to true for right to left languages like Hebrew or Arabic.
smallCaps bool If true displays text in small capital letters.
spacingBottom int Bottom padding in twentieths of a point.
spacingTop int Top padding in twentieths of a point.
tabPositions array Each entry is an associative array with the following keys and values:
  • 'type' (string) can be clear, left (default), center, right, decimal, bar and num,
  • 'leader' (string) can be none (default), dot, hyphen, underscore, heavy and middleDot,
  • 'position' (int) given in twentieths of a point.
If there is a tab and the tabPositions array is not defined the standard tab position (default of 708) will be used.
textAlign string Text alignment within paragraph. Possible values are: center, right, both and distribute.
textDirection string Text flow direction within a table cell. Possible values are: lrTb, tbRl, btLr, lrTbV, tbRlV and tbLrV.
underline string Underlines text. Possible values are: single, words, double, dotted, dash and wave.
widowControl bool Prevents Word from printing the last line of a paragraph by itself at the top of the page (widow) or the first line of a paragraph at the bottom of a page (orphan).
wordWrap bool Allows line breaking at character level (default value is false).
Return values

Void.

Code samples

Example #1

The resulting Word document looks like: