Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, October 16, 2014 5:15 AM
I am having an XML file generated dynamically (using ruby) and I'm simply having an issue with image sizing. A few people online have mentioned that they're set based on the pixel dimensions of the image. I'm not finding this to be the case.
Here's one link in particular that I was looking at: http://openxmldeveloper.org/discussions/formats/f/15/p/396/933.aspx.
The reason I know this may not be 100% the case is because I basically opened a word document, inserted 2 screenshots, and I compared the output of the 9525 (PMU) * every pixel and got different values.
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:
<wp:extent cx="5153025" cy="1053736"/><a:ext cx="5153025" cy="1053736"/>
<wp:extent cx="5553075" cy="3868694"/><a:ext cx="5553075" cy="3868694"/>
So 802 * 9525 = 7639050 and this doesn't exist anywhere in that XML output.
My goal here is to make sure that the images I'm referencing from XML are properly sized. I would like the size of the image in the word doc to be the exact size of the image itself.
Any help would be GREATLY appreciated. I've been looking around for hours and still coming up empty.
All replies (2)
Friday, October 17, 2014 8:09 AM âś…Answered
Hi altjx,
The image width/height in "cx"/"cy" should be in EMU(English Metric Unit), but not PMU. According to a code sample found in MSDN document:
Adding Images to Documents in Word 2007 by Using the Open XML SDK 2.0 for Microsoft Office
The calculation method of cx/cy is like this:
long imageWidthEMU =(long)((imageFile.Width / imageFile.HorizontalResolution) * 914400L);
long imageHeightEMU =(long)((imageFile.Height / imageFile.VerticalResolution) * 914400L);
Cx = imageWidthEMU
Cy = imageHeightEMU
- Compute the image's width in EMUs: wEmu = imgWidthPixels / imgHorizontalDpi * emuPerInch
- Compute the image's height in EMUs: hEmu = imgHeightPixels / imgVerticalDpi * emuPerInch
emuPerInch is 914400.
So besides the image width and height, you still need to use some image editing tools to get the image horizontal resolution and vertical resolution.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Tuesday, July 24, 2018 10:32 AM
Hello
If we have a very large file width and height 1937x1803 px and 72 ppi what is the calculation happening inside word to fit these images to the page nicely?