Forum


Replies: 2   Views: 1408
Unwanted space at beginning of table cell
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 dev@ams  · 14-07-2020 - 09:47

Hi,

We do get an unwanted space in docx files generated with phpdocx at the beginning of table cells.

It happens for example in this case:

<table>
    <tbody>
    <tr>
        <td style="border-bottom:solid #000000;border-left:solid #000000;border-right:solid #000000;border-top:solid #000000;width:20%;">Test</td>
        <td style="border-bottom:solid #000000;border-left:solid #000000;border-right:solid #000000;border-top:solid #000000;width:80%;">Has extra space in front when <strong>bold</strong> is used</td>
    </tr>
    </tbody>
</table>

WIth the following embedhtml settings:

'parseDivs'        => 'paragraph',
            'addDefaultStyles' => true,
            'disableWrapValue' => true,
            'useHTMLExtended'  => true,
            'downloadImages'   => true,
            'parseFloats'      => true,
            'strictWordStyles' => false,

We already tried it using `removeLineBreaks`, but that removes other spaces that we don't want to have removed.

What causes these spaces and how can we prevent these?

Posted by admin  · 14-07-2020 - 15:58

Hello,

We have run the following script using all versions of PHP from 5.2.11 to 7.4 and in all cases there's no extra space:

require_once 'classes/CreateDocx.php';

$docx = new CreateDocx();

$html = '
<table>
    <tbody>
    <tr>
        <td style="border-bottom:solid #000000;border-left:solid #000000;border-right:solid #000000;border-top:solid #000000;width:20%;">Test</td>
        <td style="border-bottom:solid #000000;border-left:solid #000000;border-right:solid #000000;border-top:solid #000000;width:80%;">Has extra space in front when <strong>bold</strong> is used</td>
    </tr>
    </tbody>
</table>
';
$options = array(
    'parseDivs' => 'paragraph',
    'addDefaultStyles' => true,
    'disableWrapValue' => true,
    'useHTMLExtended' => true,
    'downloadImages' => true,
    'parseFloats' => true,
    'strictWordStyles' => false,
);

$docx->embedHTML($html, $options);

$docx->createDocx('output');

Please send to contact[at]phpdocx.com the following information:

  • DOCX output that contains the extra blank space, for example the output of running the previous code on your server.
  • PHP version and phpdocx version you are using.
  • Program and version you are using to open it.

so we can check it. removeLineBreaks in phpdocx 10 should only remove extra line breaks added by Tidy but not other line breaks, maybe you are using an old version of phpdocx?

Regards.

Posted by admin  · 15-07-2020 - 08:30

Hello,

The problem comes from enabling disableWrapValue, please use the following options:
 
$options = array(
     'parseDivs' => 'paragraph',
    'addDefaultStyles' => true,
    'useHTMLExtended' => true,
    'downloadImages' => true,
    'parseFloats' => true,
    'strictWordStyles' => false,
);

$docx->embedHTML($html, $options);

and the extra blank spaces won't appear. Please note that disableWrapValue option is for very specific cases when using some Tidy versions with problems.

Regards.