You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Jo...@act.org on 2012/04/25 16:38:51 UTC
Extracting alt text from images using HWPF
Is it possible to get the alternative text for an image using HWPF? I am
currently using POI 3.8 and have not been able to find where this is
stored in the HWPFDocument. I would expect it to be part of
org.apache.poi.hwpf.usermodel.Picture but there does not seem to be any
methods to return alt text.
Re: Extracting alt text from images using HWPF
Posted by Jo...@act.org.
Patch submitted.
Bug ID 53165.
Re: Extracting alt text from images using HWPF
Posted by Nick Burch <ni...@alfresco.com>.
On Sat, 28 Apr 2012, Josh.Holthaus@act.org wrote:
> I did come up with a way to get the alt text from the properties of a
> picture.
Would you be able to work up a patch for HWPF that exposes this
description from the picture itself?
Also, for turning the bytes into a String, you might find it better to use
StringUtil to do it, rather than coding your own
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Extracting alt text from images using HWPF
Posted by Jo...@act.org.
I did come up with a way to get the alt text from the properties of a
picture.
/**
* Returns the alternative text stored in the EscherProperties
* @param picture
* @return
*/
public static String getAltText(Picture picture){
PICFAndOfficeArtData picfAndOfficeArtData = null;
try{
Field field = picture.getClass().getDeclaredField(
"_picfAndOfficeArtData");
field.setAccessible(true);
picfAndOfficeArtData = (PICFAndOfficeArtData)
field.get(picture);
}catch(Exception e){
logger.error("Unable to get _picfAndOfficeArtData",e);
throw new RuntimeException(e);
}
for(EscherRecord escherRecord :
picfAndOfficeArtData.getShape().getChildRecords()){
if(escherRecord instanceof EscherOptRecord){
EscherOptRecord escherOptRecord =
(EscherOptRecord) escherRecord;
for(EscherProperty property :
escherOptRecord.getEscherProperties()){
if(EscherProperties.
GROUPSHAPE__DESCRIPTION == property.getPropertyNumber()){
byte[] complexData =
((EscherComplexProperty)property).getComplexData();
byte[] altTextData = new byte
[(complexData.length/2)-1];
for(int i=0; i<altTextData.length
;i++){
altTextData[i] =
complexData[i*2];
}
return new String(altTextData);
}
}
}
}
return null;
}