Forum


Replies: 9   Views: 3758
Rtl lists generation from html
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  · 09-12-2016 - 19:41

Hello,

We recommend to use the API methods to add RTL content, as you can check on:

http://www.phpdocx.com/documentation/introduction/right-left-languages-tutorial

embedHTML doesn't include an option to set RTL.

Almost all HTML imported using the embedHTML method can include this attribute:

dir="rtl"

to set RTL direction. In the case of lists this options is missing, so we recommend you to add the RTL list using the addList method adding placeholders in each list item and then use replaceVariableByHTML (http://www.phpdocx.com/api-documentation/templates/replace-variable-html-Word-document) to replace the placeholders in the list by HTML.

Anyway, you can try this quick patch to add bidi support in lists (including dir="rtl" in each li tag). Edit the file classes/HTML2WordML.inc and in the method generateListPr add this code (around line 1964):

if ((isset($properties['dir']) && strtolower($properties['dir']) == 'rtl') ||
                (isset($properties['direction']) && strtolower($properties['direction']) == 'rtl')) {
    $stringListPr .= '<w:bidi w:val="1" />';
}

The code must be:

if (!$this->strictWordStyles) {
    if (isset($properties['background_color']) && is_array($properties['background_color'])) {
        $color = $properties['background_color'];
        $color = $this->wordMLColor($color);
        $stringListPr .='<w:shd w:val="clear"  w:color="auto" w:fill="' . $color . '" />';
    }
    $stringListPr .= $this->pPrSpacing($properties);
}
if ((isset($properties['dir']) && strtolower($properties['dir']) == 'rtl') ||
 (isset($properties['direction']) && strtolower($properties['direction']) == 'rtl')) {
    $stringListPr .= '<w:bidi w:val="1" />';
}
if (isset($properties['list_style_type']) && $properties['list_style_type'] == 'none') {
    $stringListPr .= $this->pPrIndent($properties);
}

Also don't forget to enable these options:

bidi = "true"
rtl = "true"

as explained on http://www.phpdocx.com/documentation/introduction/right-left-languages-tutorial.

Regards.