Forum


Replies: 6   Views: 3899
Getting image captions to work?
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 nicks  · 15-01-2016 - 12:02

Hi,

I've installed the latest release and trying to get to grips with image captions.

I've added a 'caption' parameter as shown below:

$captionsettings = array('text' => 'test');
$image->addImage(array('src' => $imagesrc,'imageAlign' => 'center','height' => $picvar[0],'width' => $picvar[1],'caption' => $captionsettings));

 

Though I then receive the error:

Fatal error: Call to a member function saveXML() on a non-object in /var/www/phpdocx_corporate-new2/classes/CreateDocx.inc

There is mention of:

'show_label' (string) show default value Figure

I tried setting a value here, though I guess it provides a default?

Is it possible to get demo snippet of how I should declare a caption?

Thanks

 

Posted by admin  · 18-01-2016 - 09:04

Hello,

This a simple sample about how to add image captions:

$options = array(
    'src' => 'image.png',
    'imageAlign' => 'left',
    'scaling' => 50,
    'spacingTop' => 10,
    'spacingBottom' => 0,
    'spacingLeft' => 0,
    'spacingRight' => 20,
    'textWrap' => 0,
    'borderStyle' => 'lgDash',
    'borderWidth' => 6,
    'borderColor' => 'FF0000',
    'caption' => array('show_label' => true, 'text' => 'FIRST IMAGE')
);

$docx->addImage($options);

You may read the valid parameters on the addImage API doc (http://www.phpdocx.com/api-documentation/word-content/insert-image-Word-document-with-PHP).

Regards.

 

Posted by nicks  · 20-01-2016 - 12:08

Thanks for the example, however I am not having much luck making it work:

$captionsettings = array('show_label' => true, 'text' => 'FIRST IMAGE');

$image->addImage(array('src' => $imagesrc,'imageAlign' => 'center','height' => $picvar[0],'width' => $picvar[1],'caption' => $captionsettings));

 

I get this error:

Fatal error: Call to a member function saveXML() on a non-object in /var/www/phpdocx_corporate-new2/classes/CreateDocx.inc on line 3376

 

Am I missing any other parameters?

Posted by admin  · 21-01-2016 - 08:30

Hello,

We've done some checks and everything is working fine, please post the full script. This script must illustrate the issue and be as simple as possible.

Regards.

Posted by nicks  · 22-01-2016 - 14:04

Sure, I'll email you over an example now.

Posted by jari.heinonen  · 13-04-2016 - 07:04

Hi guys,

It would be quite nice, if one could localize the default label "Figure" of image caption.

Have you any plans to make it possible?

Posted by admin  · 13-04-2016 - 11:41

Hello,

You could set the option 'show_label' as false and then use 'text' to add a custom string instead of 'Figure'. 'Figure' os a fixed default text added by Word.

Regards.