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

Release notes
  • phpdocx 15.5:
    • structured document tag checkboxes.
    • Plotly JS library is added only if at least one chart exists.
    • don't apply margin-top in textboxes that use absolute positions.
  • phpdocx 14.5:
    • improved left and right spacings in lists.
    • lists square as list type.
    • default left and right spacing styles applied when numberingAsParagraphs is true.
    • includeBlankSpacesInEmptyParagraphs option applies to heading tags.
    • excluded Symbol font-family in list items without a font-family.
    • excludeNotSupportedImageTypes option.
    • clean fillColor extra information in textboxes when Theme colors are used.
    • majorHAnsi and minorHAnsi font family styles from the asciiTheme attribute.
    • exact tr height styles in tables.
  • phpdocx 14.0:
    • conditional table styles and tblLook tag.
    • improved table styles without internal pPr and rPr styles.
  • phpdocx 13.5:
    • charts (bar column, pie, doughnut and line).
    • includeContentTypes option.
    • pPr and rPr styles in custom table styles.
    • empty font families values are not added.
  • phpdocx 13.0:
    • replaced &nbsp; with<br> when the includeBlankSpacesInEmptyParagraphs is enabled to keep empty paragraphs.
  • phpdocx 12.5:
    • RTL: paragraphs (textDirection, rtl, bidi styles), run-of-text (rtl style).
    • comments, endnotes, and footnotes added inside their own section tags with a specific class.
    • lists allow using custom symbols (Wingdings font) as list-style-type, circle type is supported.
    • simple fields: AUTHOR, COMMENTS, LASTSAVEDBY, TITLE.
    • tables: direction (btLr, tbLrV, tbRl, tbRlV), cell padding styles.
    • textboxes: margin-top, default border when none is set.
    • sections: columns.
    • tracked contents: ins and del tags.
    • highlight style added as w:pPr/w:rPr style.
  • phpdocx 12.0:
    • w:vanish style.
    • improved cell margins when only table margins are set.
    • supported on/off, 1/0 and true/false values for w:pPr and w:rPr styles.
    • improved hyperlinks and border styles.
  • phpdocx 11.0:
    • improved table borders and rowspans.
    • supported multiple checkboxes in the same paragraph.
  • phpdocx 10.0:
    • WMF images.
    • forced span styles to avoid overwriting issues when document default styles are set.
    • supported zero values when using bold and italic styles.
    • improved inheritance when applying custom paragraph and character styles.
    • w:outlineLvl tags.
    • supported tcBorders tags whyout children.
    • improved hanging attributes and tab contents.
    • span with a tabcontent class is used to transform tab tags.
  • phpdocx 9.5:
    • image alignments with a wrapper paragraph align.
    • normalized decimal values to force using dots in decimal values.
    • underline style as none when no val is set.
    • supported mixing bold styles in paragraph and run-of-text styles.
    • TOC anchors.
    • addDefaultStyles option.
    • default styles applied to block tags and span tags.
    • improved numbering transformations to support numberings such as 1.1 1.2... and numbering in custom paragraph styles.
    • w:tab as &emsp;.
    • includeBlankSpacesInEmptyParagraphs option.
    • improved importing tables with multiple colspan values.
  • phpdocx 9.0:
    • sdt tags that wrap cell tables.
    • added default values for margin-top and margin-bottom styles in the base CSS of the default plugin.
    • supported nil as value in internal cells of tables.
    • start attribute in lists.
  • phpdocx 8.5:
    • paragraph and table default styles set by a w:style tag with a w:default="1" property.
    • w:cs attributes when w:ascii doesn't exist in font tags.
    • new default values for top and bottom margins when not set in the DOCX.
    • default HTML content for empty contents such as paragraphs.
    • imported insideH, insideV, band1Horz, band2Horz, firstCol, lastCol, firstRow, lastRow tags and styles in tables.
    • increment heading indexes automatically based on style and occurrence values.
  • phpdocx 8.2:
    • comments.
    • new checks when default styles don't exist.
    • added links for endnote, footnote and comment references.
    • improved colspans and rowspans in the first row.
  • phpdocx 8.0:
    • new method.