There are 2 ways you can get the image part.
The first is to get one of the header parts, then ask it for the image part by relationship type. Search this forum for posts on how to get the header part. Then:
- Code: Select all
RelationshipsPart rp = headerpart.getRelationshipsPart();
Relationship rel = rp.getRelationshipByType(Namespaces.IMAGE);
Once you have the rel, you can do:
- Code: Select all
BinaryPart p = (BinaryPart)rp.getPart(rel);
or, for example
- Code: Select all
ImageJpegPart p = (ImageJpegPart)rp.getPart(rel);
The second, only if you already know the name of the part, is to get it directly from the parts collection. For a JPEG, something like:
- Code: Select all
ImageJpegPart p = (ImageJpegPart)wordMLPackage.getParts().get(new PartName("/word/media/image1.jpeg" ) )
Look in the samples dir for basics such as how to load the wordMLPackage from a file.
cheers .. Jason