Bulleted and ordered lists are usually an esential component of any businees oriented, legal or technical document.

Docxpresso allows for the creation of sophisticated lists with a high degree of customization.

The available list styles include:

  • Unordered lists with custom bullets:
    • disc,
    • circle
    • square and
    • none.
  • Ordered lists:
    • decimal,
    • decimal-extended (for nested lists),
    • lower-alpha or lower-latin,
    • lower-roman,
    • lower-greek,
    • upper-alpha or upper-latin and
    • upper-roman.

Unordered lists

The required method to create unordered lists is the unorderedList method which public API is given by:

Signature

public unorderedList ([$options])

Parameters

  • $options (type: array).
    This array has the following available keys and values:

    • items (type: array), a (nested) array with the items to be included in the list (plain text or document fragments). This argument is optional because the items can also be added via the listItem method.
    • style (type: string). A string of styles in CSS format.

This method basically offeres a wrapper for list elements and as such has limited its styling options to:

  • List styling:
    • list-style-type: the list bullet type.

Let su generate a simple nested list that will illustrate the basic functionality of this method:

<?php
/**
 * This sample script inserts a simple unordered nested list
 */
require_once 'pathToDocxpresso/CreateDocument.inc';
$doc = new DocxpressoCreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//insert a simple nested list
$items = array('First list item.',
               'Second entry.',
               array('First sublist element',
                     'Second sublist entry.',
                     ),
               'Last item.',
               );
$doc->unorderedList(array('items' => $items));
//include in the render method the path where you want your document to be saved
$doc->render('simple_list' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'simple_list' . $format . '">Download document</a>';

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf

If we need to have more control over the list elements formatting we should use document fragments or use the listItem method that we now pass to describe.

List items

One may include elements in a list one at a time with the help of the listItem method.

Its public API is given by:

Signature

public listItem ([$options])

Parameters

  • $options (type: array). This array has the following available keys and values:

    • text (type: mixed). It can be a string of text or a documentFragment object. This argument is optional becuase the contents may be added by chaining with other methods.

All the styling, including changes in the margins and indents should be applied to the contents that may be introduced via the paragraph, heading or text methods or directly via documentFragment objects.

Let us introduce some extra formatting in the list:

<?php
/**
 * This sample script inserts an unordered nested list
 */
require_once 'pathToDocxpresso/CreateDocument.inc';
$doc = new DocxpressoCreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//create an empty list and populate it with the listItem method
$doc->unorderedList()
        ->listItem()
            ->text(array('text' => 'First item '))
            ->text(array('text' => 'with some bold text'))->style('font-weight: bold')
            ->text(array('text' => '.'))
        ->listItem()
            ->text(array('text' => 'Second item.'))
        ->unorderedList()
            ->listItem()
                ->text(array('text' => 'First subitem '))
                ->text(array('text' => 'with some red text'))->style('color: #b70000')
                ->text(array('text' => '.'))
            ->listItem()
                ->text(array('text' => 'Second subitem.'))
            ->end('list')
        ->listItem()
            ->text(array('text' => 'Last item.'));
//include in the render method the path where you want your document to be saved
$doc->render('unordered_list' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'unordered_list' . $format . '">Download document</a>';

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf

If we would like to change the styles at the “list item level” (margins, indents, bullet color, …) we could do something like this:

<?php
/**
 * This sample script inserts an unordered nested list
 */
require_once 'pathToDocxpresso/CreateDocument.inc';
$doc = new DocxpressoCreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//create an empty list and populate it with the listItem method
$doc->unorderedList()
        ->listItem()
            ->paragraph()->style('margin-left: 3cm; color: #0000b7; text-indent: -0.4cm')
                ->text(array('text' => 'First item '))
                ->text(array('text' => 'with some bold text'))->style('font-weight: bold')
                ->text(array('text' => ' in blue and some extra margin left and a negative indent.'))
        ->listItem()
            ->text(array('text' => 'Second item.'))
        ->unorderedList()
            ->listItem()
                ->text(array('text' => 'First subitem '))
                ->text(array('text' => 'with some red text'))->style('color: #b70000')
                ->text(array('text' => '.'))
            ->listItem()
                ->text(array('text' => 'Second subitem.'))
            ->end('list')
        ->listItem()
            ->text(array('text' => 'Last item.'));
//include in the render method the path where you want your document to be saved
$doc->render('unordered_list_2' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'unordered_list_2' . $format . '">Download document</a>';

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf

Ordered lists

Ordered lists are in all analogue to unordered lists so we will be pretty brief.

Its public API is given by.

Signature

public orderedList ([$options])

Parameters

  • $options (type: array). This array has the following available keys and values:

    • items (type: array), a (nested) array with the items to be included in the list (plain text or document fragments). This argument is optional because the items can also be added via the itemList method.
    • style (type: string). A string of styles in CSS format.

This method basically offeres a wrapper for ordered list elements and as such has limited its styling options to:

  • List styling:
    • list-style-type: the numbering type (ordered lists).

Let us give us an example using the decimal-extended list style option to illustrate its behaviour (the other numberings behave exactly the same that their HTML counterparts):

<?php
/**
 * This sample script inserts an ordered nested list
 */
require_once 'pathToDocxpresso/CreateDocument.inc';
$doc = new DocxpressoCreateDocument();
$format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf
//create an empty list and populate it with the listItem method
$doc->orderedList()->style('list-style-type: decimal-extended')
        ->listItem()
            ->text(array('text' => 'First item '))
            ->text(array('text' => 'with some bold text'))->style('font-weight: bold')
            ->text(array('text' => '.'))
        ->listItem()
            ->text(array('text' => 'Second item.'))
        ->orderedList()->style('list-style-type: decimal-extended')
            ->listItem()
                ->text(array('text' => 'First subitem '))
                ->text(array('text' => 'with some red text'))->style('color: #b70000')
                ->text(array('text' => '.'))
            ->listItem()
                ->text(array('text' => 'Second subitem.'))
            ->end('list')
        ->listItem()
            ->text(array('text' => 'Last item.'));
//include in the render method the path where you want your document to be saved
$doc->render('ordered_list' . $format); 
//echo a link to the generated document
echo 'You may download the generated document from the link below:<br/>';
echo '<a href="' . 'ordered_list' . $format . '">Download document</a>';  

DOWNLOAD:download pdfdownload docdownload docxdownload odtdownload rtf