Getting Image Details For Adding To DOCX
I am adding images to a DOCX files using the WordprocessingDocument method found here (Open XML) http://msdn.microsoft.com/en-us/library/bb497430.aspx.
I can add images, but the sizing is not correct.
MainDocumentPart mainPart = doc.MainDocumentPart;
Image开发者_开发问答Part imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
using (System.IO.FileStream stream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
imagePart.FeedData(stream);
}
return AddImageToBody(doc, mainPart.GetIdOfPart(imagePart), fileName);
private static Drawing AddImageToBody(WordprocessingDocument wordDoc, string relationshipId, string filename)
{
long imageWidthEMU = 1900000;
long imageHeightEMU = 350000;
double imageWidthInInches = imageWidthEMU / 914400.0;
double imageHeightInInches = imageHeightEMU / 914400.0;
new DW.Extent();
//Define the reference of the image.
var element =
new Drawing(
new DW.Inline(
new DW.Extent() { Cx = imageWidthEMU, Cy = imageHeightEMU },
As you can see, you specify the sizes (length + width) manually. I am unable to get them dynamically. How can you get the right correct image size to pass to this code?
Thanks.
Your problem solved here: Inserting Image into DocX using OpenXML and setting the size
There is no way to solve it via instruction in the xml file. OOXML offers only <a:fill>
and <a:tile>
options.
精彩评论