I am dynamically creating Word documents using the Velocity template engine. The documents are created in XML (using the Microsoft Office 2003 WordprocessML XML standard).
I am embedding an image (encoded in Base64 format) inside the WordML in the traditional way:
<w:pict>
<v:shapeType> ... </v:shapeType>
<w:binData w:name="wordml://02000002.jpg"> [ encoded data] </w:binData>
<v:shape id="_x0000_s1026"
type="#_x0000_t75"
style="width:100%;height:100%"
o:allowoverlap="f"
>
<v:imagedata src="wordml://02000002.jpg" o:title="testimage2">
</v:imagedata>
</v:shape>
</w:pict>
The issue is with image sizing / scaling. Note the style
attribute on the <v:shape>
tag. Setting height and width to 100% does not size the image to its actual size. It sets height and width to approximately 1.04 inches which skews the image. Leaving off the height and width has the same effect. Setting height and width to auto
has the same effect.
Most annoyingly, if I open the generated document in Word 2003, right click on the image, open the Format Picture dialog, and go to the Size tab it display the correct height and width under "Original size." It even provides a "Reset" button that resizes the image to its original size (assuming the "Relative to original picture size" checkbox is checked.)
I am like: !*@&#^#% ???
So my question is:
Is there anyway in the context of WordML to get the original size values for the image (or instruct Word to use the original image size)?
If someone can help will this question, I promise I will write an in depth blog post to ensure that I will be the last person that has to deal with this.