Cookbook
- Learn phpdocx in 5 minutes
- Tutorial
- API quick guide
- HTML to Word
- HTML Extended
- Conversion plugin
- Word to HTML
- DOCXPath
- Bulk processing
- DOCXCustomizer
- Digital signature
- Cryptophpdocx
- Right to left languages
- phpdocx CLI command
- Tracking
- Artificial Intelligence
- Blockchain for documents
- JavaScript API
- Compiled mode
Change default styles when importing HTML
The embedHTML and replaceVariableByHTML methods allow to import HTML. Both methods apply some default styles for tags, unless the user predefine their values.
E.g., the following code adds a heading (h1 tag) and two paragraphs:
The only style change is for the color of the h1 tag, with a value of #b70000. As there are no mentions for other styles, phpdocx automatically applies the most similar values to the ones that MS Words uses. For example, a margin for the top and bottom of the paragraphs.
In order to overwrite automatic styles, you have to associate some new ones to your document. To delete the default margin and spacing for the paragraphs in the previous example, just define a margin style:
You can associate these styles to the document with the attribute style, a CSS stylesheet or a style of the Word document.