Jump to content

Insert image into a Word document


Clint C.

Recommended Posts

Hi guys and girls

 

I'm trying to generate Word files at runtime with custom values (the usual). The problem that I'm having is inserting the image in my document.

 

I have two ways of accessing my image:

 

Works

$imageLocation = "C:\\wamp\\www\\Qualitysheet\\Images\\chart.png";

 

Doesn't work

$imageLocation = ".\\..\\Images\\chart.png"; 

 

and I insert my image like this:

<img src='$imageLocation' width='$width' height='$height' alt='$imageAltText' />

 

First case

I can move my Word file anywhere, the picture will be shown (as it has a hard coded path).

 

Second case

I get the error "Resource Id #4" if I move my Word document to another location (because of the relative path, I understand this). I don't know how to solve this, does anyone have any ideas?

 

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/191678-insert-image-into-a-word-document/
Share on other sites

I haven't created word docs on the fly like this, but have you tried using a url to the image on the server instead of a relative image in there? if that doesn't work your going to have to see how images are saved in the word doc itself and attempt to replicate that functionality.

 

If it's an option, you may be better off creating a pdf then a word doc.

 

 

Hi there, thanks for replying.

 

The putting an image on to a server and then linking to that in the word file is something I had thought of. But what if the user loses his internet connection, then he would not see the image?

 

I think I'll have to indeed either dig deeper and see how Word saves an image or go for PDF files.

 

Thanks!

Other replies are still welcome.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.