Constants

SOURCE_LOCAL

SOURCE_LOCAL = 'local'

Image source type constants

SOURCE_GD

SOURCE_GD = 'gd'

SOURCE_ARCHIVE

SOURCE_ARCHIVE = 'archive'

SOURCE_STRING

SOURCE_STRING = 'string'

Properties

$sectionId

$sectionId : integer

Section Id

Type

integer

$docPart

$docPart : string

Document part type: Section|Header|Footer|Footnote|Endnote

Used by textrun and cell container to determine where the element is located because it will affect the availability of other element, e.g. footnote will not be available when $docPart is header or footer.

Type

string

$docPartId

$docPartId : integer

Document part Id

For header and footer, this will be = ($sectionId - 1) * 3 + $index because the max number of header/footer in every page is 3, i.e. AUTO, FIRST, and EVEN (AUTO = ODD)

Type

integer

$elementIndex

$elementIndex : integer

Index of element in the elements collection (start with 1)

Type

integer

$elementId

$elementId : string

Unique Id for element

Type

string

$relationId

$relationId : integer

Relation Id

Type

integer

$mediaRelation

$mediaRelation : boolean

Has media relation flag; true for Link, Image, and Object

Type

boolean

$collectionRelation

$collectionRelation : boolean

Is part of collection; true for Title, Footnote, Endnote, Chart, and Comment

Type

boolean

$nestedLevel

$nestedLevel : integer

Depth of table container nested level; Primarily used for RTF writer/reader

0 = Not in a table; 1 = in a table; 2 = in a table inside another table, etc.

Type

integer

$parentContainer

$parentContainer : string

Parent container type

Type

string

$source

$source : string

Image source

Type

string

$sourceType

$sourceType : string

Source type: local|gd|archive

Type

string

$watermark

$watermark : boolean

Is watermark

Type

boolean

$name

$name : string

Name of image

Type

string

$imageType

$imageType : string

Image type

Type

string

$imageCreateFunc

$imageCreateFunc : string

Image create function

Type

string

$imageFunc

$imageFunc : string

Image function

Type

string

$imageExtension

$imageExtension : string

Image extension

Type

string

$memoryImage

$memoryImage : boolean

Is memory image

Type

boolean

$target

$target : string

Image target file name

Type

string

$mediaIndex

$mediaIndex : integer

Image media index

Type

integer

Methods

setPhpWord()

setPhpWord(\PhpOffice\PhpWord\PhpWord  $phpWord = null) 

Set PhpWord as reference.

Parameters

\PhpOffice\PhpWord\PhpWord $phpWord

getSectionId()

getSectionId() : integer

Get section number

Returns

integer

setDocPart()

setDocPart(string  $docPart, integer  $docPartId = 1) 

Set doc part.

Parameters

string $docPart
integer $docPartId

getDocPart()

getDocPart() : string

Get doc part

Returns

string

getDocPartId()

getDocPartId() : integer

Get doc part Id

Returns

integer

getElementIndex()

getElementIndex() : integer

Get element index

Returns

integer

setElementIndex()

setElementIndex(integer  $value) 

Set element index.

Parameters

integer $value

getElementId()

getElementId() : string

Get element unique ID

Returns

string

setElementId()

setElementId() 

Set element unique ID from 6 first digit of md5.

getRelationId()

getRelationId() : integer

Get relation Id

Returns

integer

setRelationId()

setRelationId(integer  $value) 

Set relation Id.

Parameters

integer $value

getNestedLevel()

getNestedLevel() : integer

Get nested level

Returns

integer

getParent()

getParent() 

setParentContainer()

setParentContainer(\PhpOffice\PhpWord\Element\AbstractElement  $container) 

Set parent container

Passed parameter should be a container, except for Table (contain Row) and Row (contain Cell)

Parameters

\PhpOffice\PhpWord\Element\AbstractElement $container

isInSection()

isInSection() : boolean

Check if element is located in Section doc part (as opposed to Header/Footer)

Returns

boolean

setChangeInfo()

setChangeInfo(string  $type, string  $author, null|integer|\DateTime  $date = null) 

Set changed

Parameters

string $type

INSERTED|DELETED

string $author
null|integer|\DateTime $date

allways in UTC

__construct()

__construct(string  $source, mixed  $style = null, boolean  $watermark = false, string  $name = null) 

Create new image element

Parameters

string $source
mixed $style
boolean $watermark
string $name

Throws

\PhpOffice\PhpWord\Exception\InvalidImageException
\PhpOffice\PhpWord\Exception\UnsupportedImageTypeException

getSource()

getSource() : string

Get image source

Returns

string

getSourceType()

getSourceType() : string

Get image source type

Returns

string

setName()

setName(string  $value) 

Sets the image name

Parameters

string $value

getName()

getName() : null|string

Get image name

Returns

null|string

getMediaId()

getMediaId() : string

Get image media ID

Returns

string

isWatermark()

isWatermark() : boolean

Get is watermark

Returns

boolean

setIsWatermark()

setIsWatermark(boolean  $value) 

Set is watermark

Parameters

boolean $value

getImageType()

getImageType() : string

Get image type

Returns

string

getImageCreateFunction()

getImageCreateFunction() : string

Get image create function

Returns

string

getImageFunction()

getImageFunction() : string

Get image function

Returns

string

getImageExtension()

getImageExtension() : string

Get image extension

Returns

string

isMemImage()

isMemImage() : boolean

Get is memory image

Returns

boolean

getTarget()

getTarget() : string

Get target file name

Returns

string

setTarget()

setTarget(string  $value) 

Set target file name.

Parameters

string $value

getMediaIndex()

getMediaIndex() : integer

Get media index

Returns

integer

setMediaIndex()

setMediaIndex(integer  $value) 

Set media index.

Parameters

integer $value

getImageStringData()

getImageStringData(boolean  $base64 = false) : string|null

Get image string data

Parameters

boolean $base64

Returns

string|null

getIsWatermark()

getIsWatermark() 

Get is watermark

getIsMemImage()

getIsMemImage() 

Get is memory image

setNewStyle()

setNewStyle(mixed  $styleObject, mixed  $styleValue = null, boolean  $returnObject = false) : mixed

Set new style value

Parameters

mixed $styleObject

Style object

mixed $styleValue

Style value

boolean $returnObject

Always return object

Returns

mixed

setEnumVal()

setEnumVal(string|null  $value = null, array<mixed,string>  $enum = array(), string|null  $default = null) : string|null

Set enum value

Parameters

string|null $value
array<mixed,string> $enum
string|null $default

Throws

\InvalidArgumentException

Returns

string|null

getMediaPart()

getMediaPart() : string

Return media element (image, object, link) container name

Returns

string —

section|headerx|footerx|footnote|endnote

setMediaRelation()

setMediaRelation() 

Set relation Id for media elements (link, image, object; legacy of OOXML)

  • Image element needs to be passed to Media object
  • Icon needs to be set for Object element

setCollectionRelation()

setCollectionRelation() 

Set relation Id for elements that will be registered in the Collection subnamespaces.

checkImage()

checkImage() 

Check memory image, supported type, image functions, and proportional width/height.

Throws

\PhpOffice\PhpWord\Exception\InvalidImageException
\PhpOffice\PhpWord\Exception\UnsupportedImageTypeException

setSourceType()

setSourceType() 

Set source type.

getArchiveImageSize()

getArchiveImageSize(string  $source) : array|null

Get image size from archive

Parameters

string $source

Throws

\PhpOffice\PhpWord\Exception\CreateTemporaryFileException

Returns

array|null

getStringImageSize()

getStringImageSize(string  $source) 

get image size from string

Parameters

string $source

setFunctions()

setFunctions() 

Set image functions and extensions.

setProportionalSize()

setProportionalSize(integer  $actualWidth, integer  $actualHeight) 

Set proportional width/height if one dimension not available.

Parameters

integer $actualWidth
integer $actualHeight