Page 1 of 1

Inserting images (permissions & temp tmp files)

PostPosted: Thu Aug 05, 2010 11:10 am
by timmee
Hi
I am currently evaluateing docx4j and have struck a problem. We would be using this to produce docx documents with text and images. The images are created in the same class file and are bufferedImages (at the moment). I can'r save these and re-load into the document (no write priveliges).

is there a way I can insert these bufferedimages straight into the document as it's being built?

Cheers

Re: Inserting images

PostPosted: Thu Aug 05, 2010 8:02 pm
by jason
BinaryPartAbstractImage contains methods to create an image from a byte[] (see the AddImage sample).

So you'll need to convert your BufferedImage to a byte[] in one of the supported formats (eg jpeg, png)

That bit is easy .. see for example http://www.velocityreviews.com/forums/t ... array.html

There is one remaining issue. BinaryPartAbstractImage currently writes a tmp file when ascertaining an image's format. Until this is changed in the docx4j sources, you'll have to use your own modified copies of that code to avoid that.

ImageInfo ought to be reviewed. I notice there is now a project http://commons.apache.org/sanselan/whysanselan.html which provides a potential alternative.

Re: Inserting images (permissions & temp tmp files)

PostPosted: Mon Aug 09, 2010 10:43 am
by timmee
Fantasic

worked first time. looks like docx4j may be a keeper :D

Re: Inserting images (permissions & temp tmp files)

PostPosted: Mon Aug 09, 2010 5:54 pm
by jason
Great, nice to hear :-)