/** * Create a <wp:inline> element suitable for this image, * which can be _embedded_ in w:p/w:r/w:drawing. * @param filenameHint Any text, for example the original filename * @param altText Like HTML's alt text * @param id1 An id unique in the document * @param id2 Another id unique in the document * @param cx Image width in twip * @param link true if this is to be linked not embedded * None of these things seem to be exposed in Word 2007's * user interface, but Word won't open the document if * any of the attributes these go in (except @ desc) aren't present! * @throws Exception */ public Inline createImageInline(String filenameHint, String altText, int id1, int id2, long cx, boolean link) throws Exception { ImageSize size = imageInfo.getSize(); Dimension2D dPt = size.getDimensionPt(); double imageWidthTwips = dPt.getWidth() * 20; log.debug("imageWidthTwips: " + imageWidthTwips); long cy; log.debug("Scaling image height to retain aspect ratio"); cy = UnitsOfMeasurement.twipToEMU(dPt.getHeight() * 20 * cx / imageWidthTwips); // Now convert cx to EMU cx = UnitsOfMeasurement.twipToEMU(cx); log.debug("cx=" + cx + "; cy=" + cy); return createImageInline(filenameHint, altText, id1, id2, cx, cy, link); }
/** * Create a <wp:inline> element suitable for this image, * which can be _embedded_ in w:p/w:r/w:drawing. * @param filenameHint Any text, for example the original filename * @param altText Like HTML's alt text * @param id1 An id unique in the document * @param id2 Another id unique in the document * @param cx Image width in twip * @param link true if this is to be linked not embedded * None of these things seem to be exposed in Word 2007's * user interface, but Word won't open the document if * any of the attributes these go in (except @ desc) aren't present! * @throws Exception */ public Inline createImageInline(String filenameHint, String altText, int id1, int id2, long cx, boolean link) throws Exception { ImageSize size = imageInfo.getSize(); Dimension2D dPt = size.getDimensionPt(); double imageWidthTwips = dPt.getWidth() * 20; log.debug("imageWidthTwips: " + imageWidthTwips); long cy; log.debug("Scaling image height to retain aspect ratio"); cy = UnitsOfMeasurement.twipToEMU(dPt.getHeight() * 20 * cx / imageWidthTwips); // Now convert cx to EMU cx = UnitsOfMeasurement.twipToEMU(cx); log.debug("cx=" + cx + "; cy=" + cy); return createImageInline(filenameHint, altText, id1, id2, cx, cy, link); }