Page 1 of 1

Setting image size in XML using wp:extent and a:ext

PostPosted: Thu Oct 16, 2014 4:33 pm
by altjx
I've seen several threads on here pertaining to this topic; however, I haven't been able to successfully find an answer.

I'm modifying a Microsoft Word (.docx) file via its XML contents, and as I'm creating references to images, I'm noticing that the size of them are screwed up. I did a bit of looking around online and everyone's referring to pixel dimensions * EMUs to get this value. However, I'm not experiencing this same thing. They're stating that 1 pixel = 9525 EMUs, so therefore using the example below, 802 * 9525 would have to equal 5153025, which it doesn't.

If I take a look at image1 for example, it's 802x164, and image2 is 722x503. The wp:content and a:ext values that were generated (in respective order) are:

Code: Select all
<wp:extent cx="5153025" cy="1053736"/>               <a:ext cx="5153025" cy="1053736"/>
<wp:extent cx="5553075" cy="3868694"/>               <a:ext cx="5553075" cy="3868694"/>


which doesn't make sense.

Any help would be greatly appreciated. This is the last thing I need to resolve before becoming successful with my goal. :\

Re: Setting image size in XML using wp:extent and a:ext

PostPosted: Fri Oct 17, 2014 9:28 am
by jason
Seems to be a cross post of:

http://stackoverflow.com/questions/2639 ... nding-emus

http://stackoverflow.com/questions/2639 ... or-openxml

and may not be docx4j related?

For what its worth, in https://github.com/plutext/docx4j/blob/ ... ement.java
we have:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        public static int pxToTwip(float px) {
               
                float inch = px/DPI;  // default DPI is 96
                return inchToTwip(inch);               
        }

        public static int inchToTwip(float inch  ) {
                // 1440 twip = 1 inch;
                return Math.round(inch*1440);          
        }

        public static long twipToEMU(double twips) {           
                return Math.round(635 * twips);                        
        }

 
Parsed in 0.018 seconds, using GeSHi 1.0.8.4


Are you sure you have the size in pixels correct?

Re: Setting image size in XML using wp:extent and a:ext

PostPosted: Fri Oct 17, 2014 3:26 pm
by altjx
Got it taken care of. Thanks for your help.