transformDocAdvHTML

transformDocAdvHTML

ADVANCED / PREMIUM TRIAL

Transforms documents into HTML using native PHP classes.

Description
public transform (TransformDocAdvHTMLPlugin $htmlPlugin, [, array $options])

This method allows to transform a DOCX document, generated or not with phpdocx, into HTML preserving, as much as possible, the original formatting options.

Tags, CSS, sizes and other transformations can be customized easily extending the classes and using plugins.

You may find more info regarding this method in the Word to HTML section.

Parameters transform

htmlPlugin

Plugin used to transform the DOCX, TransformDocAdvHTMLDefaultPlugin as default.

options

The possible keys and values are:

Key Type Description
addDefaultStyles bool If true add default MS Word styles. Default as true.
includeBlankSpacesInEmptyParagraphs bool If true add a blank space to empty paragraphs. Useful to keep blank paragraphs if needed. Default as false.
includeContentTypes array If a content type is not set, its transformation is not done. Available content types: images, charts. Default all content types.
javaScriptAtTop bool Adds the JavaScript at the top of the HTML. Default as false.
numberingAsParagraphs bool If true add list numberings as paragraphs. Useful to transform complex numberings. Default as false.
returnHTMLStructure bool If true returns an array with the structure of the DOCX transformed to HTML: (css, document, endnotes, footnotes, headers, footers, javascript. metas). Default as false.
Methods and attributes TransformDocAdvHTMLPlugin

generateClassName

Function to generate class names.

setBaseCSS

Base CSS to be added when transforming the document.

Default value: '<style>p { margin-top: 0px;margin-bottom: 0px;} span.tabcontent{margin-left: 50px;} ins {color: red;} del {color: red;}</style>'.

setBaseHTML

Base HTML to be added when transforming the document.

Default value: '<!DOCTYPE html><html>'.

setBaseJavaScript

Base JavaScript to be added when transforming the document.

Default value: '<script src="https://cdn.plot.ly/plotly-2.14.0.min.js"></script>'.

setBaseMeta

Base meta tags to be added when transforming the document.

Default value: '<meta charset="UTF-8">'.

setConversionFactor

Conversion factor to transform sizes. Default as 1.3

setExtraClasses

Extra classes to add for a tag.

setGenerateSectionTags

Default as true. If false, the transformation doesn't read section tags.

setImagesAsBase64

Default as true. If false, it generates the images as files.

setOutputFilesPath

Set the output path folder of the external files (altchunk, images...). If setImagesAsBase64 is set as true, the images aren't saved to this folder.

setTag

Set a specific tag for a OOXML tag.

transformColors

Function to transform color values.

transformSizes

Function to transform size values.

Exceptions

Error while trying to open the (base) template as a zip file.

Code samples

Example #1