import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
}
return null;
}
+
+ /**
+ * Returns the width of the picture (in points).
+ */
+ public double getWidth() {
+ return Units.toPoints(ctPic.getSpPr().getXfrm().getExt().getCx());
+ }
+
+ /**
+ * Returns the depth of the picture (in points).
+ */
+ public double getDepth() {
+ return Units.toPoints(ctPic.getSpPr().getXfrm().getExt().getCy());
+ }
public String getDescription() {
return description;
XWPFPicture pic = r.getEmbeddedPictures().get(0);
CTPicture ctPic = pic.getCTPicture();
CTBlipFillProperties ctBlipFill = ctPic.getBlipFill();
-
+
assertNotNull(ctBlipFill);
CTBlip ctBlip = ctBlipFill.getBlip();
document.close();
}
+ @Test
+ public void testGetDepthWidth() throws IOException, InvalidFormatException {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
+ XWPFHeader hdr = doc.createHeader(HeaderFooterType.DEFAULT);
+ XWPFParagraph p = hdr.createParagraph();
+ XWPFRun r = p.createRun();
+
+ assertEquals(0, hdr.getAllPictures().size());
+ assertEquals(0, r.getEmbeddedPictures().size());
+
+ r.addPicture(new ByteArrayInputStream(new byte[0]), Document.PICTURE_TYPE_JPEG, "test.jpg", 21, 32);
+
+ assertEquals(1, hdr.getAllPictures().size());
+ assertEquals(1, r.getEmbeddedPictures().size());
+
+ XWPFPicture pic = r.getEmbeddedPictures().get(0);
+
+ assertEquals(pic.getWidth(), Units.toPoints(21), 0.0);
+ assertEquals(pic.getDepth(), Units.toPoints(32), 0.0);
+ }
+
}