customizeWordContent

customizeWordContent

PREMIUM TRIAL / ADVANCED

Changes content styles on the fly of documents created from scratch and templates.

Description
public customizeWordContent (array $referenceNode, array $options)
Parameters

referenceNode

An array to get the refence node to be customized.
The possible keys and values of this array are:

Key Type Description
target string document (default), style, lastSection, header, footer, numbering.
type string * (all), break, image, list, math, numbering, paragraph, run, section, style, table, table-row, table-cell, table-cell-paragraph.
contains string Contains a text string.
occurrence int Number of occurrence from 1.
attributes array Contains a specific attribute key and value.
parent string Main document body as default, allows to set any parent or a specific one. w:body (default), '/' (any parent) or any other specific parent (/w:tbl/, /w:tc/, /w:r/...).
reference array To be used with header and footer targets: positions (array) 1, 2... based on the sectPr contents order, sections (array) 1, 2..., types (array) first, even, default
customQuery string Custom xpath query, overwrites any other reference.

options

Changes to be applied.

break elements

Key Type Description
type string line, page

image elements

Key Type Description
borderColor string hexadecimal color: FF0000.
borderStyle string Possible values are:
  • solid
  • dot
  • dash
  • lgDash
  • dashDot
  • lgDashDot
  • lgDashDotDot
  • sysDash
  • sysDot
  • sysDashDot
  • sysDashDotDot
borderWidth int Given in emus (1cm = 360000 emus).
height int Given in emus (1cm = 360000 emus).
imageAlign string Image alignment: right, center,...
spacingBottom int Given in emus (1cm = 360000 emus).
spacingLeft int Given in emus (1cm = 360000 emus).
spacingRight int Given in emus (1cm = 360000 emus).
spacingTop int Given in emus (1cm = 360000 emus).
width int Given in emus (1cm = 360000 emus).

list elements. The same options as 'paragraph' and:

Key Type Description
depthLevel int Depth level.
type string 0 (clear), 1 (inordinate) (default), 2 (numerical) or the name of the created list.

numbering elements

Key Type Description
levelAlign string Level align.
levelText string Level text.
numberingFormat string Numbering format.
numberingStart int Numbering start value.

paragraph elements

Key Type Description
backgroundColor string Hexadecimal color: FF0000.
bidi bool If true enables bidi.
bold boolean If true the text will be shown in bold characters.
caps boolean If true displays text in capital letters.
color string Hexadecimal color value: 'FF0000', '000000'...
dstrike boolean If true displays text in doubleStrikeThrough.
em string Emphasis mark type: none, dot, circle, comma, underDot.
font string Font family: 'Arial', Calibri'...
fontSize int Font size in points.
headingLevel int The heading level.
italic bool If true displays the text in italics.
keepLines bool Keeps (whenever possible) all the current paragraph lines on the same page.
keepNext bool Keeps (whenever possible) in the same page the current paragraph with next paragraph.
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.
pStyle string Word style to be used. Run parseStyles() method to check all available paragraph styles.
rtl bool If true enables RTL.
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.
strike boolean If true displays text in strikethrough.
textAlign string Text alignment within paragraph. Possible values are: center, right, both and distribute.
underline string Underlines text. Possible values are: single, words, double, dotted, dash and wave.
underlineColor string Underlines text with a color: 'FF0000', '000000'...
vanish bool Uses a vanish style.
widowControl bool Widow control.

run elements

Key Type Description
bold boolean If true the text will be shown in bold characters.
caps boolean If true displays text in capital letters.
characterBorder array Adds a border to the character. Keys and values: 'type' => none, single, double, dashed..., 'color' => ffffff, ff0000, 'spacing'=> 0, 1, 2..., 'width' => in eights of a point.
color string Hexadecimal color value: 'FF0000', '000000'...
dstrike boolean If true displays text in doubleStrikeThrough.
em string Emphasis mark type: none, dot, circle, comma, underDot.
font string Font family: 'Arial', Calibri'...
fontSize int Font size in points.
highlight string Colors: black, blue, cyan, green, magenta, red, yellow, white, darkBlue, darkCyan, darkGreen, darkMagenta, darkRed, darkYellow, darkGray, lightGray, none.
italic bool If true displays the text in italics.
position int Position value. Positive value for raised and negative value for lowered.
rtl bool If true enables RTL.
scaling int Scaling value, 100 is the default value.
smallCaps bool If true displays text in small capital letters.
spacing int character spacing, positive value for expanded and negative value for condensed.
strike boolean If true displays text in strikethrough.
underline string Underlines text. Possible values are: single, words, double, dotted, dash and wave.
underlineColor string Underlines text using a color: : 'FF0000', '000000'...
vanish bool Uses a vanish style.

section elements

Key Type Description
gutter int Gutter in twips (used for binding).
height int Section height in twips.
marginBottom int Bottom margin for this section in twips.
marginFooter int Footer margin in twips.
marginHeader int Header margin in twips.
marginLeft int Left margin for this section in twips.
marginRight int Right margin for this section in twips.
marginTop int Top margin for this section in twips.
numberCols int Number of columns for the section.
orient string Section page orientation (portrait or landscape).
space int Column spacing in twips (used for binding).
width int Section width in twips.

style elements. The same options as 'paragraph'.

table elements

Key Type Description
border string Border type: none, single, double, dashed, threeDEngrave, threeDEmboss, outset, inset... This value can be overridden for each side with the use 'borderTop', 'borderRight', 'borderBottom' and 'borderLeft' properties.
borderColor string Hexadecimal color value: 'FF0000', '000000'... This value can be overridden for each side with the use of 'borderTopColor', 'borderRightColor', 'borderBottomColor' and 'borderLeftColor' properties.
borderSpacing int Border spacing in points. This value can be overridden for each side with the use of 'borderTopSpacing', 'borderRightSpacing', 'borderBottomSpacing' and 'borderLeftSpacing' properties.
borderWidth int Border size in eigths of a point. This value can be overridden for each side with the use of 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth' and 'borderLeftWidth' properties.
cellMargin mixed An integer or an array with keys: top, right, bottom and left. The values are given in twentieths of a point.
cellSpacing int Separation among cells. Given in twentieths of a point (twips).
columnWidths mixed An integer or a zero-based array with the widths of each column in twentieths of a point.
indent int Left table margin in twentieths of a point (twips).
tableAlign string Table alignment. Possible values are: center, left or right.
tableStyle string Word table style id (you may run parseStyles method to check for the available styles in phpdocx or your particular template).
tableWidth array Its possible keys and values are:
  • 'type' (pct, dxa) pct if the value refers to percentage and dxa if the value is given in twentieths of a point (twips).
  • 'value' (int.)

table-row elements

Key Type Description
height int Height in twentieths of a point.
minHeight int Minimum height in twentieths of a point.

table-cell elements

Key Type Description
backgroundColor string Hexadecimal color value: 'FF0000', '000000'...
border string Border type: none, single, double, dashed, threeDEngrave, threeDEmboss, outset, inset... This value can be overridden for each side with the use 'borderTop', 'borderRight', 'borderBottom' and 'borderLeft' properties.
borderColor string Hexadecimal color value: 'FF0000', '000000'... This value can be overridden for each side with the use of 'borderTopColor', 'borderRightColor', 'borderBottomColor' and 'borderLeftColor' properties.
borderSpacing int Border spacing in points. This value can be overridden for each side with the use of 'borderTopSpacing', 'borderRightSpacing', 'borderBottomSpacing' and 'borderLeftSpacing' properties.
borderWidth int Border size in eigths of a point. This value can be overridden for each side with the use of 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth' and 'borderLeftWidth' properties.
cellMargin mixed An integer or an array with keys: top, right, bottom and left. The values are given in twentieths of a point.
fitText bool If true fits the text to the size of the cell.
rowspan int The row span of that particular table cell.
vAlign string Vertical align of text: top, center, both or bottom.
width int Preferred cell width in twentieths of a point (twips).

other options

Key Type Description
customAttributes array Custom attributes and values.
Exceptions

Method not available.

Code samples

Example #1

Release notes
  • phpdocx 15.5:
    • math type.
  • phpdocx 15.0:
    • table-cell-paragraph type.
    • widowControl option.
  • phpdocx 14.5:
    • existing row styles not required when updating trPr styles.
  • phpdocx 14.0:
    • rtl and bidi styles.
  • phpdocx 13.5:
    • numbering target.
  • phpdocx 13.0:
    • color style in run content types.
  • phpdocx 12.5:
    • keepLines and keepNext styles.
  • phpdocx 12.0:
    • strike, dstrike and vanish styles.
    • improved working with multiple sections that contain multiple headers and footers.
  • phpdocx 11.0:
    • space option.
  • phpdocx 10.0:
    • supported w:eastAsia in fonts.
  • phpdocx 9.5:
    • header and footer targets.
  • phpdocx 7.0:
    • new method.