Add image with jOpenDocument in odt document (writer)

I am trying the jOpenDocument API and I want to add / insert an image. Can I do it using this API? I am interested in jOpenDocument because it allows me to create a template and then process the document using Java (which I don't think is possible with ODFDOM from Apache).

The only thing I found is that I can do something like this:

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"));  
ddoc.saveAs(outFile);  

      

As you can see, this is only href

and as a result my odt file will not be portable as it depends on the image path.

Are there any built-in methods in the jOpenDocument API so I can insert images into my odt file?

+3


source to share





All Articles