I am trying to add a shadow effect to an image using docx4j. I am creating the image using the following:
- Code: Select all
// ByteBuffer myImage ...
byte[] bytes = myImage.array();
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage
.createImagePart(wordMLPackage, bytes);
int docPrId = 1;
int cNvPrId = 2;
Inline inline = imagePart.createImageInline(image_ID,
image_description, docPrId, cNvPrId, true);
I tried using the tool to convert a docx into code and obtained the following code for setting my shapeProperties:
- Code: Select all
public CTShapeProperties createIt() {
org.docx4j.dml.ObjectFactory dmlObjectFactory = new org.docx4j.dml.ObjectFactory();
CTShapeProperties shapeproperties = dmlObjectFactory.createCTShapeProperties();
// Create object for effectLst
CTEffectList effectlist = dmlObjectFactory.createCTEffectList();
shapeproperties.setEffectLst(effectlist);
// Create object for outerShdw
CTOuterShadowEffect outershadoweffect = dmlObjectFactory.createCTOuterShadowEffect();
effectlist.setOuterShdw(outershadoweffect);
// Create object for srgbClr
CTSRgbColor srgbcolor = dmlObjectFactory.createCTSRgbColor();
outershadoweffect.setSrgbClr(srgbcolor);
>:- No code generator for package null
// Create object for alpha (wrapped in JAXBElement)
CTPositiveFixedPercentage positivefixedpercentage = dmlObjectFactory.createCTPositiveFixedPercentage();
JAXBElement<org.docx4j.dml.CTPositiveFixedPercentage> positivefixedpercentageWrapped = dmlObjectFactory.createCTSRgbColorAlpha(positivefixedpercentage);
srgbcolor.getEGColorTransform().add( positivefixedpercentageWrapped);
positivefixedpercentage.setVal( 70000 );
outershadoweffect.setBlurRad( new Long(190500) );
outershadoweffect.setDist( new Long(0) );
outershadoweffect.setDir( new Integer(0) );
outershadoweffect.setSx( new Integer(100000) );
outershadoweffect.setSy( new Integer(100000) );
outershadoweffect.setKx( new Integer(0) );
outershadoweffect.setKy( new Integer(0) );
outershadoweffect.setAlgn(org.docx4j.dml.STRectAlignment.TL);
// Create object for xfrm
CTTransform2D transform2d = dmlObjectFactory.createCTTransform2D();
shapeproperties.setXfrm(transform2d);
// Create object for ext
CTPositiveSize2D positivesize2d = dmlObjectFactory.createCTPositiveSize2D();
transform2d.setExt(positivesize2d);
positivesize2d.setCx( 5731510 );
positivesize2d.setCy( 2059598 );
transform2d.setRot( new Integer(0) );
// Create object for off
CTPoint2D point2d = dmlObjectFactory.createCTPoint2D();
transform2d.setOff(point2d);
point2d.setY( 0 );
point2d.setX( 0 );
// Create object for ln
CTLineProperties lineproperties = dmlObjectFactory.createCTLineProperties();
shapeproperties.setLn(lineproperties);
// Create object for noFill
CTNoFillProperties nofillproperties = dmlObjectFactory.createCTNoFillProperties();
lineproperties.setNoFill(nofillproperties);
shapeproperties.setBwMode(org.docx4j.dml.STBlackWhiteMode.AUTO);
// Create object for prstGeom
CTPresetGeometry2D presetgeometry2d = dmlObjectFactory.createCTPresetGeometry2D();
shapeproperties.setPrstGeom(presetgeometry2d);
// Create object for avLst
CTGeomGuideList geomguidelist = dmlObjectFactory.createCTGeomGuideList();
presetgeometry2d.setAvLst(geomguidelist);
presetgeometry2d.setPrst(org.docx4j.dml.STShapeType.RECT);
return shapeproperties;
}
The missing part is how to now set this shapeproperties on the inline.
I tried with:
- Code: Select all
CTShapeProperties shapeProperties = createIt();
inline.getGraphic().getGraphicData().getPic().setSpPr(shapeproperties);
but the resulting word does not open...
Any help/suggestion is welcome
Thanks for reading