embedHTML

embedHTML

BASIC / ADVANCED / PREMIUM

Inserts HTML content into the Word document.

Description
public embedHTML ( string $html [, array $options] )

This method allows the insertion of HTML into the current Word document.

Practically all HTML tags and CSS styles are supported.

This method transforms HTML directly into WordML and it is compatible with any DOCX reader such as LibreOffice, OpenOffice, Google Docx and others.

You may find a more detailed explanation of this useful method in the HTML to Word section of the API documentation.

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.

To embed symbols such as ∞ or Ω, please check that the PHP mbstring extension is installed and enabled.

To download images from remote URLs, please check that allow_url_fopen is enabled in the PHP config. If the remote images use HTTPS, please check that PHP is using a valid certification file and the SSL configuration is correct: More information.

Parameters

html

The HTML code to be translated into WordML: it could be a string or the path to a file.

options

The possible keys and values are:

Key Type Description
addDefaultStyles bool True as default, if false prevents adding default styles when strictWordStyles is false.
baseURL string The base URL used to complete the relative paths of links and images.
cssEntityDecode bool If true uses html_entity_decode to parse CSS, useful when using font families with non-ASCII names.
customListStyles bool If true checks if there is a custom list style with that name and uses it.
disableWrapValue bool If true disable using a wrap value with Tidy to prevent extra blank spaces. Default as false.
downloadImages bool If true inserts the images into the docx document, otherwise just links them as an external source.
filter string Only renders the filtered contents. It could be an string denoting an id ('#myId'), a class ('.myClass'), a HTML tag or a valid XPath expression ('//expression').
forceNotTidy bool False as default. If true, avoid using Tidy. Only recommended if Tidy can't be installed.
generateCustomListStyles bool If true generates automatically the custom list styles from the list styles (decimal, lower-alpha, lower-latin, lower-roman, upper-alpha, upper-latin, upper-roman).
isFile bool True for files and false for strings.
parseAnchors bool If true parses the anchors included in the HTML code.
parseDivs string paragraph or table. By default the method parses the div elements as containers.
parseFloats bool If true preserves the floating properties of images and tables.
removeLineBreaks bool If true removes extra line breaks that can be generated when transforming HTML that includes strings without a parent tag.
strictWordStyles bool If true ignores all CSS styles and uses the styles set via the wordStyles option (see next).
useHTMLExtended bool If true allows using HTML Extended tags. False as default. Only available in Premium licenses.
wordStyles array One may associate different Word styles to HTML classes, ids or tags.
For example:
  • array('.myClass' => 'LightGridPHPDOCX', '#myId' => 'LightListAccent6PHPDOCX')
Code samples

Example #1

The resulting Word document looks like: