Inserting Images in ODT

1,849 views
Skip to first unread message

Marc H.

unread,
Jul 8, 2010, 8:33:18 AM7/8/10
to jOpenDocument
Hi,

is there any way to insert Images (e.g. PNG-Files) into ODT-(Writer)-
Documents using jOpenDocument?

Regards,
Marc

Sylvain Cuaz

unread,
Jul 9, 2010, 12:54:55 PM7/9/10
to jopend...@googlegroups.com
Le 08/07/2010 14:33, Marc H. a �crit :

> Hi,
>
> is there any way to insert Images (e.g. PNG-Files) into ODT-(Writer)-
> Documents using jOpenDocument?

Hi,
Not for the moment. You can only replace an image anchored in a cell with MutableCell.setImage()

Sylvain,
ILM Informatique

Marc H.

unread,
Jul 21, 2010, 3:11:58 AM7/21/10
to jOpenDocument
> 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

Guillaume Maillard

unread,
Jul 21, 2010, 5:14:38 AM7/21/10
to jopend...@googlegroups.com
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. <onlyfo...@googlemail.com>

nico

unread,
Aug 4, 2010, 11:56:39 AM8/4/10
to jOpenDocument
Hi, could anyone provide an example on how to do it please ?
I have to generate documents with dynamics image and i'm a bit lost
right now...

Marc H.

unread,
Aug 4, 2010, 12:24:36 PM8/4/10
to jOpenDocument
> Hi, could anyone provide an example on how to do it please ?
> I have to generate documents with dynamics image and i'm a bit lost
> right now...

Hi,

wasn't the description I gave above sufficient for you?
Could you describe your problem a bit more in detail?

Just in case, I'll sum up my above post:

1) Insert a placeholder image in your ODT template
2) Position it the way you like the final Image to appear
3) Name the image
4) Use the Java-Code I posted above to substitute the placeholder by
the real image.

Cheers,
Marc.

nico

unread,
Aug 5, 2010, 6:13:23 AM8/5/10
to jOpenDocument
Hello,

Yes it works like that (even if i've to create a web-page to send me
these image), but these mutable cell could help me to solve another
problem.
Correct me if i'm wrong:
You can't put a 'field' in a cell, this means you have to create the
cell in the code, and not in the template (so the user who create the
template can't create it). So i asked myself if it would be possible
to create an unique mutable cell where i can put an image, or another
variable.

nico.


Marc H.

unread,
Aug 5, 2010, 7:15:18 AM8/5/10
to jOpenDocument
Hi;

> You can't put a 'field' in a cell, this means you have to create the
> cell in the code, and not in the template (so the user who create the
> template can't create it).

not sure, if this might help you:
On my System, (OpenOffice 3.2.1; Windows) inserting fields directly
into a table's cell (in ODT) did not work; but it is possible to
insert the fields somewhere else in the document (not into the table)
and then copy&pasting them to the location you want them to appear
(e.g. the table)...

Cheers,
Marc

nico

unread,
Aug 5, 2010, 8:05:10 AM8/5/10
to jOpenDocument
> not sure, if this might help you:
> On my System, (OpenOffice 3.2.1; Windows) inserting fields directly
> into a table's cell (in ODT) did not work; but it is possible to
> insert the fields somewhere else in the document (not into the table)
> and then copy&pasting them to the location you want them to appear
> (e.g. the table)..

that's the first trick that i tried and it didn't work ^^
anyway thanx for your help and the job you did to replace an image!

regards,
nico.

Marc H.

unread,
Aug 5, 2010, 8:37:00 AM8/5/10
to jOpenDocument
> that's the first trick that i tried and it didn't work ^^
> anyway thanx for your help and the job you did to replace an image!


What do you mean concretely by "it didn't work"?
Doesn't pasting the copied field get you the result you expected?
Or can't you copy the field ? Or not even insert it?

Cheers,
Marc.

jOpenDocument, Guillaume

unread,
Aug 5, 2010, 8:38:50 AM8/5/10
to jopend...@googlegroups.com
Hi,

We will release a new version of the plugin this week.
This kind of issue is supposed to be fixed in the new version of the plugin.

Regards,
Guillaume

nico

unread,
Aug 5, 2010, 9:21:04 AM8/5/10
to jOpenDocument
I was talking about "copy the field, paste it in the cell". Well it
was my bad, the template is an export from a .doc document and i
didn't mind about it before. I just tried on a new .odt and it worked.
It's nice to know that it will be fixed soon!

regards,
nico
Reply all
Reply to author
Forward
0 new messages