XWPFPictureData picData = (XWPFPictureData) doc.getRelationById(relationId);
// Create the drawing entry for it
try {
CTDrawing drawing = run.addNewDrawing();
CTInline inline = drawing.addNewInline();
// Do the fiddly namespace bits on the inline
// (We need full control of what goes where and as what)
String xml =
"<a:graphic xmlns:a=\"" + CTGraphicalObject.type.getName().getNamespaceURI() + "\">" +
"<a:graphicData uri=\"" + CTGraphicalObject.type.getName().getNamespaceURI() + "\">" +
"<pic:pic xmlns:pic=\"" + CTPicture.type.getName().getNamespaceURI() + "\" />" +
"</a:graphicData>" +
"</a:graphic>";
inline.set(XmlToken.Factory.parse(xml));
// Setup the inline
inline.setDistT(0);
inline.setDistR(0);
inline.setDistB(0);
inline.setDistL(0);
CTNonVisualDrawingProps docPr = inline.addNewDocPr();
long id = getParagraph().document.getDrawingIdManager().reserveNew();
docPr.setId(id);
/* This name is not visible in Word 2010 anywhere. */
docPr.setName("Drawing " + id);
docPr.setDescr(filename);
CTPositiveSize2D extent = inline.addNewExtent();
extent.setCx(width);
extent.setCy(height);
// Grab the picture object
CTGraphicalObject graphic = inline.getGraphic();
CTGraphicalObjectData graphicData = graphic.getGraphicData();
CTPicture pic = getCTPictures(graphicData).get(0);
// Set it up
CTPictureNonVisual nvPicPr = pic.addNewNvPicPr();