Hi Marc,

Thank you for your contribution, we will add a method in order to replace an
Image
the way you suggest.

It will be included in the next release.

Regards,
Guillaume

2010/7/21 Marc H. <onlyfoolsw...@googlemail.com>

> > Hi,
> >         Not for the moment. You can only replace an image anchored in a
> cell with MutableCell.setImage()
> >
> > Sylvain,
> > ILM Informatique
>
> Thanks for your reply.
> I found a solution for my specific problem anyway. Will post it here,
> 'cause it might help someone else, who wants to  insert/replace images
> in ODT:
>
> In your template, you have to insert an existing image as a
> placeholder. Position and format it the way you want it to appear in
> the final document.
> Important: Name the image. This is done by selecting "Picture" from
> the image's context menu, then choosing "Options" and setting the
> field "Name".
>
>  final File outFile = new File("output.odt");
>  final String bcfile = "image.png";
>  final JavaScriptFileTemplate template = new
> JavaScriptFileTemplate("template.odt");
>
>  final ODSingleXMLDocument ddoc = template.createDocument();
>  ddoc.getDescendantByName("draw:frame",
> "pC_LSBarcode").setAttribute("href", "file:///" + bcfile,
> Namespace.getNamespace("xlink", "http://www.w3.org/1999/xlink";)); //
> adjust the String "pC-LSBarcode" to the name of the image you have set
> in the template
>  ddoc.saveAs(outFile);
>
> Note, that the image does _not_ get embedded into the output-file
> (only a reference/link gets embedded); so you have to make sure, the
> image-file is accessible under the url you've set in the code.
> In fact, these files are not really "portable" (which is ok in my
> case, 'cause I render PDFs from the files afterwards, where the images
> get embedded; the odt is only kind of temp-file in my scenario).
>
> Maybe you could encapsulate that code (or a similar solution) in a
> method like JavaScriptFileTemplate.replaceImage in one of the
> following releases?
>
> Cheers,
> Marc

Reply via email to