Forum


Replies: 6   Views: 1934
With corporate version 5.5, is it possible to embed an image in a table cell with the addimage() fea
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  · 15-03-2019 - 07:56

Hello,

We have tested the following script with phpdocx Corporate 5.5 and it works perfectly:

<?php

require_once 'classes/CreateDocx.inc';

$docx = new CreateDocxFromTemplate('../../files/TemplateSimpleText.docx');

$first = 'PHPDocX';
$multiline = 'This is the first line.\nThis is the second line of text.';

$variables = array('FIRSTTEXT' => $first, 'MULTILINETEXT' => $multiline);
$options = array('parseLineBreaks' =>true);

$docx->replaceVariableByText($variables, $options);

$link = new WordFragment($docx);
$options = array(
    'url' => 'http://www.google.es'
);

$link->addLink('Link to Google', $options);

$image = new WordFragment($docx);
$options = array(
    'src' => '../../img/image.png'
);

$image->addImage($options);

$valuesTable = array(
    array(
        'Title A',
        'Title B',
        'Title C'
    ),
    array(
        'Line A',
        $link,
        $image
    )
);


$paramsTable = array(
    'tableAlign' => 'center',
    'columnWidths' => array(1000, 2500, 3000),
    );

$docx->addTable($valuesTable, $paramsTable);

$docx->createDocx('output');

The image is added to the table correctly.

Maybe you are trying to add a WordFragment image to a WordFragment table and then add it to the document, and phpdocx 5.5 doesn't allow it; or the image source isn't a local file but a stream resource.

phpdocx has added a lot improvements when working with WordFragments since the release of phpdocx 5.5, we recommend you to upgrade your license to be able to use them and other features such as streamMode when adding images.

Regards.