Page 1 of 1

Binding a "Picture Content control" to an URL

PostPosted: Sat Feb 19, 2011 5:01 am
by beric
Hello,

Could you tell me if the following scenario can be implemented with docx4j (I have tried without success) :
I have in my document a Picture content control linked to a file via an URL (I have selected "Link to File" when inserting my picture). The document does not contain the image data, but only the link.
I would like to bind it to an element from my custom XML file that contain an URL (for example "<image>http://www.example.com/image.jpg</image>)
Optionally, I would be able to use repeats and insert a list of linked images ("<images><image>http://www.example.com/image1.jpg</image>.<image>http://www.example.com/image2.jpg</image></images>").
Is this possible ?

Thank you

Eric

Re: Binding a "Picture Content control" to an URL

PostPosted: Sat Feb 19, 2011 9:10 am
by jason
I don't think Word contemplates doing this with a normal picture content control. (It would pay to do some further checking, before implementing the below though)

We could add support for it to the OpenDoPE convention easily enough. Some brainstorming follows..

One way might be to use a picture content control, but have a tag od:externalImage. The problem with this is that Word might not like to open such a docx (or it might just show an image with a X).

The other is to use a normal text content control, with the same tag od:externalImage.

We might want some other parameters, such as scaling. Also, should there be a content type parameter, or is that guessed from the filename?

To save precious characters (tag length field is of limited length), maybe the tag should be od:extImg. It would point to an xpath id.

I think if you wrapped such a content control in a repeat, your list of linked images would just work. Subject of course to these other parameters (eg all being the same content type?). So maybe these other parameters should be on the image element in your custom xml file, for example: <image contenttype="image/jpeg">http://www.example.com/image1.jpg</image>

Let me know your thoughts. Once we've got a good idea what we need, I'll implement it (or you are welcome to, of course).

Re: Binding a "Picture Content control" to an URL

PostPosted: Fri Feb 25, 2011 10:07 am
by jason
Eric

Could you please explain your motivation for wanting to bind it to a URL?

Is it just a matter of convenience, so you don't have to programmatically include the image in your XML?

Or is it because you want to keep the file size down? Or is there a possibility that the image at the URL will be altered, and you want that change to automatically flow through into a bunch of documents?

I ask because this affects the design of the feature:-

One possibility would be to use a picture content control (which has the benefit that it looks like a picture control to the person designing the document in Word, and allows the user to set the image size), but then, in the pre-processing step, remove the control entirely, and replace it with a WordML image pointing to the external image (ie a linked image: this approach would give you a real URL based image).

Another possibility would be to use a picture content control (as above), but then, in the pre-processing step, fetch the external image, and inject it into the element in your custom xml which would ordinarily contain the image data. Word would then just handle this as an ordinary a data-bound image (ie an embedded image).

Or docx4j could provide both, with a switch in the tag telling it whether to link or embed.

jason wrote:One way might be to use a picture content control, but have a tag od:externalImage. The problem with this is that Word might not like to open such a docx (or it might just show an image with a X)


Turns out Word seems to have 4 different cases for the content of the element which is bound to a picture:

1. valid image data (normal case):display it
2. element is empty: display an empty picture control
3. element contains a url: ignore it; display whatever image is already pointed to in the sdt content (rel)
4. other string: display the red X / image can't be displayed text.