Forum


Replies: 2   Views: 1568
Import external stylesheet file
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  · 04-11-2019 - 07:27

Hello,

We recommend you to check the examples available on https://www.phpdocx.com/documentation/introduction/html-to-word-PHP. You can apply CSS styles using style tags:

<head>
    <style>
        p {font-style: italic;}
        p.header {font-size: 20px; font-weight: bold;}
        div.footer {font-size: 10px;}
    </style>
</head>

external CSS files:

<head>
<link href="styles.css" type="text/css" rel="stylesheet" />
</head>

and inline styles:

<tr>
    <td style="background-color: #ffff00">Cell 1 1</td>
    <td>Cell 1 2</td>
</tr>

CSS styles must be applied each time embedHTML or replaceVariableByHTML are called.

UPDATE: HTML Extended (https://www.phpdocx.com/documentation/introduction/html-extended-to-word-PHP) , available in Premium licenses, includes addBaseCSS to set a base CSS used for all HTML conversions in the same script.

Regards.

Posted by jhanley  · 04-11-2019 - 22:59

Right, I'm already prepending a string containing inline style classes. Example:

$style = "<style>
p, span[style] {
  font-family: Arial;
  font-size: 7.5pt;
}
</style>";

I just thought phpdocx might provide a method for loading external stylesheets.

That said, I will simply roll my own solution for loading an external text file. Thanks.