You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Mike Dawson <mi...@gmail.com> on 2009/12/12 18:44:36 UTC

Modify bitmap images w/ HWPF?

Hi All,

I'd like to try and modify images that are in a word document - I can
see the images in the picturestable however this seems somewhat read
only.  Actually I want to make a new FOSS tool for automatically
resizing the images in any abstract document so that it can be easily
sent over a low bandwidth link.  Many folks of course just throw in
the huge digital camera picture and then wonder why the document
doesn't want to send when 20 people share 256kbps.

I read the Javadoc for the PicturesTable class and it indicated that
the picture data itself is part of the document.  To be sure I opened
the doc with POIFS and checked the size of components:

Doc entry:CompObjSize = 106
Dir: ObjectPool
Doc entry:1TableSize = 2112
Doc entry:DocumentSummaryInformationSize = 116
Doc entry:SummaryInformationSize = 172
Doc entry:WordDocumentSize = 192834
Doc entry:OleSize = 20

The Javadoc from PicturesTable says that a picture has a unicode
representation character .  I read also read relevant parts of the MS
Word spec PDF.

As far as I can see then what I need to do is:

1. Read the data stream info to find out where header for the picture
is in the stream

2. Read the data of that picture, make a new smaller version of it,
and check the resulting filesize

3. Modify that header, then replace the header data, leave the rest of
the document unmodified.

Using the above technique one could perform any arbitary modification
on the image data (e.g. filters etc)

I would much appreciate any tips / validation / warning from anyone
more experienced with the format than I am.  Will definitely put this
on the wiki or my blogs as a use case.  If there's a way of
contributing this to the API I would be happy to do so - I guess if I
modify the data stream of the parent document object that should
remain there so that when it's next saved etc. the modification would
take efffect.

Many Thanks!

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org