This project is read-only.

problems with addImage/addMemoryImage

Oct 12, 2012 at 7:01 PM

I've been unable to add an image to a document using PHPWord, though the same images are being successfully added to a presentation using PHPPowerPoint.  the DOCX file is generated successfully with the text I added, however the images are not visible (there's a large amount of white space where the image should be).

the code for adding the images is very simple, I feel:

foreach($charts as $chart)
  $section = $doc->createSection();

  $section->addText($chart['title'], 'titleFont', 'titleParagraph');

  $section->addImage($chart['image_path'], array(
    'align' => 'center'

an example of what image_path might contain: /var/www/html/ ..... /charts/3/500x350.png

I've tried mucking with the path, and accidentally caused "file could not be found or is not of support type"-type errors from PHPWord, suggesting that it is usually finding my image, AND it is of a supported type.  and again, these same paths/images have been used to generate presentations with PHPPowerPoint.  (I'm offering downloads for the user in many formats, which all look to these PNGs.)  I've also tried various combinations of 'align', 'width', 'height' attributes for the image styling.

if it would help to see more of the code, I'm happy to copy/paste it.  I can also provide a sample DOCX generated by the code if needed.

Oct 15, 2012 at 3:16 AM

This maybe help you ,have a look.

Oct 15, 2012 at 6:09 AM
Edited Oct 15, 2012 at 6:11 AM

I saw that thread, but it was unfortunately not helpful for me.

HOWEVER: I've discovered something new: the images from my PHPWord-generated DOCX files load up fine in Microsoft Office, but not in OpenOffice!  (I usually use OpenOffice.)  I've never noticed OpenOffice failing to load images before, so I suspect this is due to a difference in how OpenOffice and MS Office read DOCX files, and how PHPWord specifically generates the DOCX files.

if I had to guess, I'd guess OpenOffice is being more-strict about the DOCX format, while MS Office is being less-strict, but I really can only guess.  I tried poking around MS's Open XML SDK to see if I could learn anything, but learning the Open XML format is... a lot of work; I suspect my boss will tell me it's not worth the time, and it's not something I'd want to do for fun :P

a new question: in your opinion, is this a bug in PHPWord, or OpenOffice?  (should I file a bug report with OpenOffice?)