Bug 54383 - Can't determine picture size and scale
Summary: Can't determine picture size and scale
Alias: None
Product: POI
Classification: Unclassified
Component: HWPF (show other bugs)
Version: 3.9-FINAL
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2013-01-08 07:52 UTC by fenyvesi.laszlo.78
Modified: 2016-07-27 08:07 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
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.