Forum


Replies: 3   Views: 2079
Lists' indentations
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 rapidtech  · 25-03-2020 - 10:35

I can't find a way to control the indentation of the list in the way I need it. I have Premium subscription and I am using embedHTML to create DOCX from HTML. The lists numeration is done by using the createListStyle function. What I need is to have nested lists with 100% page width, but different indent for the first line where the list marker is. Also, I need a space between a marker and a text. This could be done by using list-style-position: inside; but it's not supported by phpDOCX. 
The createListStyle function has hanging param, but from the documentation it's not clear how does it work and what value/units it takes.
The exact example of the output document I need you can find here - http://joxi.ru/eAOYBbpS9boYOm

Posted by admin  · 25-03-2020 - 11:23

Hello,

You need to use left and hanging options available in createListStyle. For example:

$docx = new CreateDocx();

$latinListOptions = array();
$latinListOptions[0]['type'] = 'upperLetter';
$latinListOptions[0]['format'] = '%1.';
$latinListOptions[0]['left'] = 1440;
$latinListOptions[0]['hanging'] = 720;
$latinListOptions[1]['type'] = 'decimal';
$latinListOptions[1]['format'] = '%2.';
$latinListOptions[1]['left'] = 2160;
$latinListOptions[1]['hanging'] = 720;
$docx->createListStyle('mylist', $latinListOptions);

$html = '
<ul class="mylist">
    <li>TEXT TEXT TEXT.</li>
    <br>
    <ul>
        <li><span style="text-decoration: underline;">TEXT</span>. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.</li>
        <li><span style="text-decoration: underline;">TEXT</span>. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.</li>
    </ul>
    <li>TEXT TEXT TEXT.</li>
    <br>
    <ul>
        <li><span style="text-decoration: underline;">TEXT</span>. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.</li>
        <li><span style="text-decoration: underline;">TEXT</span>. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.</li>
    </ul>
</ul>';
$docx->embedHTML($html, array('customListStyles' => true));

Please note that you can also create a custom list style using MS Word and import it using importListStyle to be applied when transforming HTML.

About hanging, from the documentation page:

hanging  int  The extra space for the numbering, should be big enough to accommodate it, the default is 360.

It's the space used by the numbering before the item contents. Both options are set using twips (integer value) (https://wordribbon.tips.net/T011388_Words_Native_Measurement_Unit.html).

Regards.

Posted by rapidtech  · 25-03-2020 - 14:13

Thank you for a quick response. Now I see what the hanging and left are doing. But still, I need a bit different. I need the text to be 100% page width and the indents only applied for the first row in a list - http://joxi.ru/Vm6xLGqF4kW10A 

Posted by admin  · 25-03-2020 - 15:34

Hello,

First line indentation isn't a numbering property but a paragraph one.

phpdocx doesn't support applying first line indentation to li tags through CSS, only paragraph (p) tags and list-style-type: none are supported. You can accomplish it using HTML Extended available in Premium licenses with the data-listppr property:

$latinListOptions = array();
$latinListOptions[0]['type'] = 'upperLetter';
$latinListOptions[0]['format'] = '%1.';
$latinListOptions[0]['left'] = 1440;
$latinListOptions[0]['hanging'] = 720;
$latinListOptions[1]['type'] = 'decimal';
$latinListOptions[1]['format'] = '%2.';
$latinListOptions[1]['left'] = 2160;
$latinListOptions[1]['hanging'] = 720;
$docx->createListStyle('mylist', $latinListOptions);

$indentation = htmlentities('<w:ind w:left="680" w:firstLine="357" />');

$html = '
<ul class="mylist">
    <li>TEXT TEXT TEXT.</li>
    <br>
    <ul>
        <li data-listppr="'.$indentation.'"><span style="text-decoration: underline;">TEXT</span>. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.</li>
        <li data-listppr="'.$indentation.'"><span style="text-decoration: underline;">TEXT</span>. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.</li>
    </ul>
    <li>TEXT TEXT TEXT.</li>
    <br>
    <ul>
        <li data-listppr="'.$indentation.'"><span style="text-decoration: underline;">TEXT</span>. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.</li>
        <li data-listppr="'.$indentation.'"><span style="text-decoration: underline;">TEXT</span>. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.</li>
    </ul>
</ul>';
$docx->embedHTML($html, array('customListStyles' => true, 'useHTMLExtended' => true));

Please note that MS Word has some limitations when mixing paragraph and numbering indentations such as trying to apply a hanging when setting the first line paragraph style. You can check them trying to create that list with MS Word.

Regards.