Forum


Replies: 2   Views: 1459
Having issue to convert html to docx using createdocx class
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 21-11-2020 - 07:48

Hello,

We recommend you read the available documentation about HTML to DOCX:

https://www.phpdocx.com/documentation/cookbook/convert-html-to-word

https://www.phpdocx.com/documentation/introduction/html-to-word-PHP

For example, about div tags as explained in the previous pages:

div: Although this tag is probably the most frequent in modern HTML code, it does not have a direct translation into Word. phpdocx offers different parsing options:
Only use it for the CSS inheritance and parse consequently its child elements.
Parse them as a "p" element with the option "parseDivs" set to "paragraph" (this may be an useful option when using HTML code coming from a WYSIWYG editor).
Parse it as a table with the option "parseDivs" set to "table". This may be the most accurate option if one may decide to preserve all available formatting but may produce complicated Word documents that may be later difficult to edit manually (if that is an interesting option).

And about tables:

Defining widths in tables
In order to correctly assign widths to tables' columns it is advisable to define the width of the table as well as its cells.

If you don't set widths to tables (table and td tags), you set automatic values that are read correctly by MS Word but not other DOCX readers, so it's recommended to apply widths to tables when adding them.

phpdocx includes options and support contents/styles to get the same output in all DOCX readers and return the best transformation and output. To understand how to use the library properly, we recommend you read the available documentation.

Regards.