addHtml

addHtml

BASIC / ADVANCED / PREMIUM

Inserts HTML and CSS into the PowerPoint presentation.

Description
public addHtml($html, $position, $options = array())

This method allows the insertion of HTML into the PowerPoint presentation.

To embed accents and other non-ASCII characters such as á or ü, please check that the PHP Tidy extension and the PHP mbstring extension are installed and enabled.

Parameters

html

HTML and CSS content to be transformed.

position

Key Type Description
placeholder array

The content is added in a placeholder of the layout. One of the following options can be used to get the text box.

  • 'name' (string) placeholder name.
  • 'descr' (string) placeholder alt text (descr) value.
  • 'position' (int) placeholder position by order. 0 is the first order position.
  • 'type' (string) title (Title), body (Body), ctrTitle (Centered Title), subTitle (Subtitle).
new array

A new position is generated.

  • 'coordinateX' (int) EMUs (English Metric Unit).
  • 'coordinateY' (int) EMUs (English Metric Unit).
  • 'sizeX' (int) EMUs (English Metric Unit).
  • 'sizeY' (int) EMUs (English Metric Unit).
  • 'name' (string) placeholder internal name. If not set, a random name is generated.
  • 'order' (int) set the display order. Default after existing contents. 0 is the first order position. If the order position doesn't exist add after existing contents.
  • 'textBoxStyles' (array) See addTextBox for text box styles.

options

Key Type Description
disableWrapValue bool If true disable using a wrap value with Tidy to prevent extra blank spaces. Default as false.
forceNotTidy bool False as default. If true, avoid using Tidy. Only recommended if Tidy can't be installed.
insertMode string

Insert mode if the position contains an existing content:

  • append
  • replace

Default as append.

parseCSSVars bool If true parses CSS variables.
Supported HTML contents and CSS styles
  • a tags

    • see text element styles
  • br tags

  • p, h1, h2, h3, h4, h5, h6 tags

    • background-color
    • dir: ltr, rtl
    • text-align: left, center, right
  • span, b, cite, em, i, s, strong, var tags

    • see text element styles
  • text element styles

    • background-color
    • color
    • font-family
    • font-size
    • font-style: italic, oblique
    • font-weight: bold, bolder, 700, 800, 900
    • letter-spacing
    • text-decoration: line-through, underline
Exceptions

PHP Tidy is not enabled.

Position not valid.

Code samples

Example #1

The resulting PPTX looks like:

Release notes
  • phppptx 3.0:
    • CSS variables.
    • root and only-child selectors.
    • improved CSS media query handling.
    • CSS 8-digit HEX colors added as 6-digit HEX colors.
  • phppptx 2.5:
    • default HTML content when adding an empty content.
  • phppptx 2.0:
    • breaks.
  • phppptx 1.0:
    • new method.