Forum


Replies: 1   Views: 71
Top and bottom table cell margins using native docx to pdf

Posted by jlw98r  · 10-10-2024 - 09:02

In PhpDocx 15.5 Premium, when I add cell margins to a table the top and bottom margins appear in the DOCX but are lost when transforming to a PDF with the native plugin. The left and right margins appear as expected. How to I change the top and bottom table cell padding for a PDF using the native plugin?

Here is some example code using 'cellMargin' => 400, but the same happens if I set it using individual keys, e.g. 'cellMargin' => ['top' => 400, 'bottom' => 400].

$tableValues = [
    ['One', 'Two'],
    ['Three', 'Four'],
    ['Five', 'Six']
];

$tableParams = array(
    'cellMargin' => 400,
);

$docx = new CreateDocx();
$docx->addTable($tableValues, $tableParams);
$docx->createDocx('example.docx');
$dompdf = new Dompdf();
$transform = new TransformDocAdvNative();
$transform->transformDocument('example.docx', 'example.pdf', ['dompdf' => $dompdf]);

Posted by admin  · 10-10-2024 - 09:56

Hello,

Please apply margins as cell styles instead of (or in addition to) table styles:

$tableValues = [
    [
        ['value' => 'One', 'cellMargin' => 400],
        ['value' => 'Two', 'cellMargin' => 400],
    ],
    [
        ['value' => 'Three', 'cellMargin' => 400],
        ['value' => 'Four', 'cellMargin' => 400],
    ],
    [
        ['value' => 'Five', 'cellMargin' => 400],
        ['value' => 'Six', 'cellMargin' => 400],
    ],
];

$docx = new CreateDocx();
$docx->addTable($tableValues);
$docx->createDocx('example.docx');

Regards.