Forum


Replies: 6   Views: 2092
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 Bouillou  · 14-03-2019 - 16:02

Hello,

With corporate version 5.5, is it possible to embed an image in a table cell with the addImage() feature? Today only a link is created in the cell of a table and the image is not accessible outside the server.

<w:p><w:r><w:rPr><w:noProof></w:noProof></w:rPr><w:drawing><wp:inline distT="0" distB="0" distL="0" distR="0"><wp:extent cx="3390900" cy="5276850"></wp:extent><wp:effectExtent l="0" t="0" r="0" b="0"></wp:effectExtent><wp:docPr id="247100553" name="0 Imagen" descr="/www/prod/app/../../data/documents/object/1/1/5b8f80ea046e7.png"></wp:docPr><wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"></a:graphicFrameLocks></wp:cNvGraphicFramePr><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:nvPicPr><pic:cNvPr id="0" name="/www/prod/app/../../data/documents/object/1/1/5b8f80ea046e7.png"></pic:cNvPr><pic:cNvPicPr></pic:cNvPicPr></pic:nvPicPr><pic:blipFill><a:blip r:embed="rId33876377" cstate="print"></a:blip><a:stretch><a:fillRect></a:fillRect></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"></a:off><a:ext cx="3390900" cy="5276850"></a:ext></a:xfrm><a:prstGeom prst="rect"><a:avLst></a:avLst></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r></w:p>

And is the streamMode option is available for the Corportate 5.5?

Best regards,

Sébastien

Posted by admin  · 14-03-2019 - 16:19

Hello,

Yes, you need to create a WordFragment with an image and then add the WordFragment to the cell table.

Please check and run the example Core/addTable/sample_2.php available in the package you are using. The XML you post is the internal OOXML image content, files are added in the word/media folder of the DOCX.

The streamMode option is available since the release of phpdocx 7.5 (https://www.phpdocx.com/news/post/phpdocx-v7-5-release-notes/213).

Regards.

Posted by Bouillou  · 14-03-2019 - 16:26

Thank you for your reply.

I am already using the same code than in your exemple. The only difference is that I am using CreateDocxFromTemplate constuctor instead of CreateDocx constuctor. The text displayed in the table cell is the wordML code posted in the first post.

Is there a limitation?

Best regards,

Sébastien

Posted by Bouillou  · 15-03-2019 - 07:44

Hello,

I have adapted the sample_2.php code to use CreateDocxFromTemplate class and it is working. 

So, to hepl me, can you tell me in which case the image is not displayed and it is the wordML code instead? Perhaps an image access problem? But the file_exists function is working in the addImage method, so the image is well accessible.

Best regards,

Sébastien

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.

Posted by Bouillou  · 15-03-2019 - 10:04

Hello,

Thank you very much for your support. The problem was on my side.

By the way, is the new versions have a fully backward compatibility with version 5.5? I mean is there any code adaptations required to upgrade or it is straight forward?

Best regards,

Sébastien

Posted by admin  · 15-03-2019 - 10:11

Hello,

The same scripts should work correctly without doing changes. Just note that instead of INC extensions, the classes use PHP extensions since the release of phpdocx 8. Using phpdocx 7.5 or previous you need to do:

require_once 'classes/CreateDocx.inc';

And phpdocx 8 or newer needs:

require_once 'classes/CreateDocx.php';

Anyway, if after doing the upgrade you have any issue please write to contact[at]phpdocx.com and we'll be able to help you.

Regards.