Bug 54383

Summary: Can't determine picture size and scale
Product: POI Reporter: fenyvesi.laszlo.78
Component: HWPFAssignee: POI Developers List <dev>
Severity: critical    
Priority: P2    
Version: 3.9-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description fenyvesi.laszlo.78 2013-01-08 07:52:38 UTC
FileInputStream fis = new FileInputStream(docRealPath);
        HWPFDocument doc = new HWPFDocument(fis);
        Picture pic = doc.getPicturesTable().getAllPictures().get(0);
        pic.getWidth(); //gives -1
        pic.getHeight(); //gives -1
        pic.getVerticalScalingFactor() //NullPointerException at org.apache.poi.hwpf.usermodel.Picture.getVerticalScalingFactor(Picture.java:491)
        pic.getHorizontalScalingFactor() //NullPointerException at org.apache.poi.hwpf.usermodel.Picture.getHorizontalScalingFactor(Picture.java:429)
        pic.getDxaGoal() //NullPointerException at org.apache.poi.hwpf.usermodel.Picture.getDxaGoal(Picture.java:378)
        pic.getDyaGoal() //NullPointerException at org.apache.poi.hwpf.usermodel.Picture.getDyaGoal(Picture.java:407)

So I can't determine the size of the picture in the Word document. It is an MSWord 97/2000/XP format.
Comment 1 fenyvesi.laszlo.78 2013-01-08 07:54:01 UTC
It is an MSWord document with one picture inserted from file (.jpg).
Comment 2 Dominik Stadler 2016-07-26 19:30:41 UTC
It's a long time since your bug-report, but can you attach a sample-file which allows to reproduce this? Otherwise it is impossible to fix anything here...
Comment 3 fenyvesi.laszlo.78 2016-07-27 07:16:50 UTC
thank you, but meanwhile I solved it with poi-3.14-beta1, pic.getHorizontalScalingFactor(), pic.getVerticalScalingFactor(), pic.getDxaGoal(), pic.getDyaGoal()

	        PICFAndOfficeArtData data = new PICFAndOfficeArtData(pic.getRawContent(), 0);
	        dxaGoal = data.getPicf().getDxaGoal();
	        dyaGoal = data.getPicf().getDyaGoal();
	        aspectRatioX = data.getPicf().getMx();
	        aspectRatioY = data.getPicf().getMy();
Comment 4 Dominik Stadler 2016-07-27 08:07:31 UTC
Ok, thanks for the note, so I close this as having a workaround/solution.