Forum


Replies: 6   Views: 2584
Html to word - vertical text
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 gmakstutis  · 15-04-2019 - 07:11

Hi,

I'm using the Drupal plugin.

In CSS we can make text vertical using:

.vertical{
writing-mode: vertical-rl
}

But this does not translate into the word document.

Is there a way to get vertical text through CSS for HTML-to-Word?

Posted by admin  · 15-04-2019 - 08:06

Hello,

You can use a dir attribute to set a text direction in paragraphs and cells with the following values: lrTb, tbRl, btLr, lrTbV, tbRlV, tbLrV . Or use a custom paragraph style, on https://www.phpdocx.com/documentation/introduction/html-to-word-PHP (Using native Word formatting with HTML section) you can read more information about using custom paragraph styles with HTML to DOCX transformations.

Regards.

Posted by gmakstutis  · 15-04-2019 - 14:30

Maybe I'm missing something...

I've tried:

<td style="dir:btLr">

<div style="dir:btLr">

<span style="dir:btLr">

.vert{
dir: btLr;
}

None of these is resulting in vertical text in my docx.

Posted by admin  · 15-04-2019 - 15:14

Hello,

You can use that property with paragraphs and cells, not with span tags. If you want to use div tags a p tags, you need to enable the parseDivsAsPs option (https://www.phpdocx.com/api-documentation/word-content/embed-html-Word-document-with-PHP).

These are the available values for that option:

  • lrTb Left to Right, Top to Bottom
  • tbRl Top to Bottom, Right to Left
  • btLr Bottom to Top, Left to Right
  • lrTbV Left to Right, Top to Bottom Rotated
  • tbRlV Top to Bottom, Right to Left Rotated
  • tbLrV Top to Bottom, Left to Right Rotated

This is a simple sample that set tbRl as text direction for one cell content in a table:

$html = '<table border="1" style="border-collapse: collapse" width="600">
            <tbody>
                <tr width="600">
                    <td style="background-color: yellow">1_1</td>
                    <td rowspan="3" colspan="2" dir="tbRl">Rotated text</td>
                </tr>
                <tr width="600">
                    <td>Some random text.</td>
                </tr>
                <tr width="600">
                    <td>
                        <ul>
                            <li>One</li>
                            <li>Two <b>and a half</b></li>
                        </ul>
                    </td>
                </tr>
                <tr width="600">
                    <td>3_2</td>
                    <td>3_3</td>
                    <td>3_3</td>
                </tr>
            </tbody>
        </table>';
$docx->embedHTML($html);

You can also use custom paragraphs styles.

Regards.

Posted by gmakstutis  · 15-04-2019 - 15:58

Still no joy.

I'm seeing no change with any of these:

<td style="dir:tbRl;">content</td>
<td style="dir:tbRlV;">content</td>

Could this have to do with the fact that I'm using the Drupal 8 plugin? Is something turned off?

Posted by gmakstutis  · 15-04-2019 - 16:00

I've just seen the problem. I'm including it in <style></style> when it is not.

Sorry....

Posted by admin  · 16-04-2019 - 17:25

Hello,

Yes, you need to set it as an attribute.

Regards.