Forum


Replies: 1   Views: 2335
Specifying html table column widths in pdf (libreoffice)
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 skilltran  · 01-04-2019 - 05:38

We are trying to generate a report in HTML and also offer it in DOCX and PDF options to users.  The report includes tables of data, and to format correctly, some columns in the tables are wider than others.  By using CSS to define the widths of the columns in the first row (the <th> cells for the heading row), this works well in HTML.  We were able to get it to work correctly in the DOCX export (viewed in Microsoft Word) by adding the table width also.

However, when we export to PDF or open the DOCX in LIbreOffice, the columns in the table all have the same width, which goofs up the layout.

Here is a simplified example that demonstrates the behavior:

<?php

require_once 'classes/CreateDocx.php';

$html = '<html>' .
                '<head><style type="text/css">' .
                '.grd { border-collapse: collapse; }' .
                '.grd th { background: rgb(249, 250, 251); border: 1px solid rgb(221, 221, 221); padding: 0.3em 0.5em; font-weight: 700; font-size: 11px; text-align: center; }' .
                '.grd td { border: 1px solid rgb(221, 221, 221); padding: 0.3em 0.5em; }' .
                '</style></head>' .
                '<body>' .
                '<table class="grd" style="width: 672px;">' .
                        '<thead>' .
                        '<tr><th style="width: 120px;">Code</th><th style="width: 230px;">Title</th><th style="width: 70px;">SVP</th><th style="width: 70px; padding: 0;">Strength</th><th style="width: 90px;">SOC</th><th style="width: 90px;">Search</th></tr>' .
                        '</thead><tbody>' .
                        '<tr><td style="text-align: center;">000.000-000</td><td>First thing on the list of titles</td><td style="text-align: center;">4</td><td style="text-align: center;">L</td><td style="text-align: center;">00-0000</td><td style="text-align: center;">1-Direct</td></tr>' .
                        '<tr><td style="text-align: center;">000.000-000</td><td>Second item on the list of titles</td><td style="text-align: center;">4</td><td style="text-align: center;">L</td><td style="text-align: center;">00-0000</td><td style="text-align: center;">1-Direct</td></tr>' .
                        '</tbody></table>' .
                '</body></html>';

$docx = new CreateDocx();
$docx->modifyPageLayout('letter', array( 'marginTop' => 720, 'marginBottom' => 720, 'marginLeft' => 1080, 'marginRight' => 1080 ));
$docx->embedHTML($html);
$docx->createDocx('example1.docx');

$path1 = realpath('example1.docx');
$path2 = str_replace('.docx', '.pdf', $path1);
$transform = new TransformDocAdvLibreOffice();
$transform->transformDocument($path1, $path2, array('x_method'=>'script'));

?>

Configuration:
PHPDOCX 9.0
LibreOffice 6.1.5

The development environment is Windows, but production environment is Linux.

What can be done to fix the HTML ​table layout?

Thanks!
Herb & Jeff
 

Posted by admin  · 01-04-2019 - 06:22

Hello,

Please check the information available on https://www.phpdocx.com/en/forum/default/topic/1755, Please download phpdocx 9 again from MY PHPDOCX page, we have tested your HTML and it's working correctly.

Regards.