addShape

addShape

TRIAL / ADVANCED / PREMIUM

Inserts different types of shapes into a Word document.

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

This method inserts a shape into your Word document.

The available types include:

  • arcs of a circle (filled or not)
  • bezier curves (filled or not)
  • straight lines
  • polylines
  • rectangles
  • rectangles with rounded corners
  • arbitrary shapes (VML paths)
  • ovals
  • straightArrow
  • arrowLeft
  • arrowRight
  • customShape
Parameters

type

arc, curve, line, polyline, rect, roundrect, shape, oval, straightArrow, arrowLeft, arrowRight, customShape.

options

The possible keys and values are:

Key Type Description
width int Shape width given in points.
height int Shape height given in points.
position string The possible values are: absolute, relative.
marginTop int Top margin given in points.
marginLeft int Left margin given in points.
relativeToHorizontal string margin, page, text, char.
relativeToVertical string margin, page, text, line.
z-index int Equivalent to the CSS z-index property. Choose a high positive number to make sure that the shape is over the text or a negative number if you want the shape to be behind the text.
strokecolor string The chosen line color in hexadecimal value: #ff0000, #00ffff.
strokeweight float The width of the line in points: 1.0 pt, 3.5 pt...
fillcolor string The chosen fill color in hexadecimal value: #ff0000, #00ffff.
textContent mixed WordFragment, a plain text string or an array with same parameters used in the addText method.
imageContent string File path to the image to be added.

Options for specific types:

Key Type Description
arc
startAngle int The angle of the tangent line at the initial point of the arc.
endAngle int The angle of the tangent line at the final point of the arc.
line and curve
from string The x and y coordinates of the initial point in the format "x,y".
to string The x and y coordinates of the final point in the format "x,y".
control1 string The final control point for the bezier curve (it does not apply for plain lines) in the format "x,y".
control2 string The final control point for the bezier curve (it does not apply for plain lines) in the format "x,y".
roundrect
arcsize float A number describing the "roundness" of the rectangle corners: 0.5, 1.8.
shape
path string The VML path describing the shape. You need a working knowledge of the VML standard.
coordsize string The VML path describing the shape. You need a working knowledge of the VML standard.
straightArrow, arrowLeft, arrowRight, shape, customShape
extraShapeStyles string Extra shape styles.
opacity int 0 to 100.
rotation int Shape rotation.
customShape
customShape string Custom shape XML.
Exceptions

Image does not exist.

Image format is not supported.

Code samples

Example #1

The resulting Word document looks like:

Release notes
  • phpdocx 14.5:
    • straightArrow, arrowLeft, arrowRight, customShapeType, opacity, rotation, extraShapeStyles, relativeToHorizontal and relativeToVertical shape types and options.
  • phpdocx 12.0:
    • imageContent option.
  • phpdocx 9.5:
    • textContent option.