Forum


Replies: 3   Views: 1514
How to get nested numeric lists?
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  · 26-11-2019 - 14:05

I have the following HTML code

$docx = new CreateDocx();
$html = '
            <style>
                ol.decimal {
                        counter-reset: item;
                }
                
                ol.decimal li {
                        display: block;
                        position: relative;
                }
                
                ol.decimal li:before {
                        content: counters(item, ".")".";
                        counter-increment: item;
                        position: absolute;
                        margin-right: 100%;
                        right: 10px;
                }
            </style>
            <ol class="decimal">
                <li>Item</li>
                <li>Item</li>
                <li>Item</li>
                <li>Item
                    <ol class="decimal">
                        <li>Item</li>
                        <li>Item</li>
                        <li>Item</li>
                        <li>Item
                            <ol class="decimal">
                                <li>Item</li>
                                <li>Item</li>
                                <li>Item</li>
                                <li>Item</li>
                            </ol>
                        </li>
                    </ol>
                </li>
            </ol>';
$docx->embedHTML($html);
$docx->createDocx('output');

Which should give me in a result

1. Item

2. Item

2. Item

4. Item

    4.1 Item

    4.2 Item

    4.3 Item

    4.4 Item

        4.4.1 Item

        4.4.2 Item

        4.4.3 Item

        4.4.4 Item

But instead of this, I am getting simple numeric lists. I guess that 'counter-increment' is not supported. Please, advise me on how to achieve the necessary look?

Posted by admin  · 26-11-2019 - 16:50

Hello,

You need to use custom list styles. On https://www.phpdocx.com/documentation/introduction/html-to-word-PHP (Lists section) you can read all information about this feature and a sample; this same sample is also available in the package (examples/Core/embedHTML/sample_2.php file). 

Regards.

Posted by rapidtech  · 27-11-2019 - 09:06

Thank you, it's working fine. One more moment, after generating a DOCX I need to transform it to PDF. But the resulted PDF file instead of numbers has bullets. I need the exact same look

$docx = new CreateDocx();

$decimalOptions = array();
$decimalOptions[0]['type'] = '1';
$decimalOptions[0]['format'] = '%1.';
$decimalOptions[1]['type'] = '1';
$decimalOptions[1]['format'] = '%1.%2.';
$decimalOptions[2]['type'] = '1';
$decimalOptions[2]['format'] = '%1.%2.%3';
$docx->createListStyle('decimal', $decimalOptions);

$html = '
<ol class="decimal">
    <li>First item.</li>
    <li>Second item with subitems:
        <ol>
            <li>First subitem.</li>
            <li>Second subitem.
                <ol>
                    <li>First subitem.</li>
                    <li>Second subitem.</li>
                </ol>
            </li>
        </ol>
    </li>
    <li>Third subitem.</li>
</ol>';
$docx->embedHTML($html, array('customListStyles' => true));
$docx->createDocx('test.docx');


$transform = new TransformDocAdvPDF('test.docx');
$transform->transform('test.pdf');

 

Posted by admin  · 27-11-2019 - 10:33

Hello,

To transform that content, you need to use the conversion plugin based on LibreOffice, not the native one.

On https://www.phpdocx.com/documentation/conversion-plugin you can read all information about installing and using the conversion plugin.

On http://Supported OOXML tags and attributes when using the native method (Supported OOXML tags and attributes when using the native method section) are detailed the supported contents and styles by the native transformation.

Regards.