You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by OS User <os...@hotmail.co.uk> on 2010/11/19 10:43:49 UTC

v3.7 HWPF image error

Hi,
 
Using scratchpad 3.1-FINAL, I could load a Word 2003 document containing gifs and text placeholders, substitute data for the placeholders and write it out.
 
I now need to be able to process documents containing symbols, for which I need the 3.7 release but the following simple test fails as soon as I insert a jpg/gif/png into the document:

File f = new 
File("ProcessedDoc.doc");
HWPFDocument document = new HWPFDocument(new FileInputStream("Source.doc"));
FileOutputStream fos = new FileOutputStream(f);
document.write(fos);
fos.flush();
fos.close();
 
The new document is created and contains the image but the text is full of question marks and has lost all formatting.
 
I've looked through the POI tests but I can't see anything that seems to exercise this.
 
It seems that adding the symbol support to 3.1-FINAL (locally only) and having the my app depend on the fork may be the quickest way out of my current problem. Does this sound feasible or does the symbol support require deep changes. I've looked at the code which references the unicode value and the link to the actual symbol and it wasn't obvious to me where the symbol processing boundary was - but then I know nothing about the Word format (and I'm grateful to POI for that!).
 
Any suggestions or code samples would be appreciated - particularly of the 'no that works, do it this way' variety :-)
 
btw, the existing method of text substutution seems to have changed because it also now fails (when testing on a document without an image):
 
loop over keys ..
String key = ..
String value = ..
 
Range range = document.getRange();
String text = range.text();
int offset = text.indexOf(key);
if (offset >= 0) {
 range.replaceText(key, value, offset)
..
 
but I'll get to that if the recommendation is to stick with 3.7 (I know there are tests for that)..
 
Thanks,
 
Derek