Cookbook
Tips to convert HTML to Word
The addHtml and its counterpart for templates, replaceVariableHtml, allow to convert HTML with CSS to PPTX. To achieve the maximum similarity with the original HTML and avoid any errors, it is necessary to follow some good practices.
Tidy, incorrect tagging, accents and other non ASCII characters
For a proper HTML import, it is mandatory that the tags and styles are correctly opened and closed. In other words, that the structure of the code is right. phppptx uses the PHP extension Tidy (http://php.net/manual/en/book.tidy.php) to correct the HTML and generate a valid tagging. You can install this extension in any operating system with PHP.
To import HTML with accents, we also recommend installing the PHP mbstring extension to auto detect mime encoding.
Warning
If you haven't installed the Tidy extension, errors may ocurr, like appearing the CSS styles in the document, import with errors the HTML or not displaying accents and other non ASCII characters.
Transforming HTML without Tidy
Although using PHP Tidy is highly recommended when using addHtml and replaceVariableHtml, these methods include the forceNotTidy option to ignore the Exception thrown by phppptx if PHP Tidy is not available. This option is only recommended if PHP Tidy can't be installed.
Enabling this option and adding special entity codes such as letters with accents or symbols, require working with HTML entities and UTF-8.
This can be done by setting the UTF-8 encoding in the HTML string
Or automatically using htmlentities:
Or manually in the HTML string to be transformed: