Hi,

I'm trying to add some custom properties to a word document using HPSF.
It seems to work fine, besides that the information is not displayed in
the properties of the document when I open it using MS Word. Also the
information will be removed from the document when saving it in Word.
(I used a hex-editor to be sure, that everything is stored in the doc)

This is what I do in detail:

I create a new Section within the DocumentSummaryInformation and add a dictionary and a tag "info".

(I used the WriteAuthorAndTitle example from the HowTo)

--- begin of code ---

MutablePropertySet mps = new MutablePropertySet(si);
MutableSection s = null;
Map hm = new HashMap();

// If there is already a second section, then write to it.      
// Works fine and the information stays within the document
// even after saving it with MS Word
if (mps.getSectionCount() > 1){
  s = (MutableSection) mps.getSections().get(1);
  hm = s.getDictionary();
} // if not, create a new one
else {
  s = new MutableSection();
  s.setDictionary(hm);
  s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID);
  mps.addSection(s);
}

[...]

String info = "Hello World";

// size +2, becaus position 0 is the dictionary
// and 1 is the codepage
long posInfo = hm.size() + 2;

hm.put(new Long(posInfo), "info");

// creating a new property
MutableProperty p = new MutableProperty();
p.setType(Variant.VT_LPSTR);
p.setValue(info);
p.setID(posInfo);

s.setProperty(p);

// write to file etc.
InputStream pss = mps.toInputStream();
de.createDocument(name, pss);

--- end of code ---

I compared the output of POI to a document I created in MS Word using
the ReadCustomPropertySets example and the only difference I found was
the codepage set to 1200 by POI and 1252 by MS Word.

Any hints what I am doing wrong?

Thanks in advance,

Sven


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/

Reply via email to