public static Run AddImageParagraph(MainDocumentPart mainpart, string filename, string SigId) { SigId = SigId.Replace("/", ""); byte[] imageFileBytes; Bitmap image = null; // Open a stream on the image file and read it's contents. using (FileStream fsImageFile = System.IO.File.OpenRead(filename)) { imageFileBytes = new byte[fsImageFile.Length]; fsImageFile.Read(imageFileBytes, 0, imageFileBytes.Length); image = new Bitmap(fsImageFile); } string extension = Path.GetExtension(filename); string ExtensionText = "image/jpeg"; if (extension == "png") ExtensionText = "image/png"; double MaxImageWidth = 0.2; double imgWidth = image.Width; double imgHeight = image.Height; double itmp = imgWidth / MaxImageWidth; double HorResolution = 1;//image.HorizontalResolution; double verResolution = 1;//image.VerticalResolution; double emuWidth = imgWidth / HorResolution / itmp; double emuHeight = imgHeight / verResolution / itmp; long imageWidthEMU = (long)((emuWidth) * 914400L); long imageHeightEMU = (long)((emuHeight) * 914400L); // add this is not already there try { if (mainpart.GetPartById(SigId) == null) { var imagePart = mainpart.AddNewPart<ImagePart>(ExtensionText, SigId); using (BinaryWriter writer = new BinaryWriter(imagePart.GetStream())) { writer.Write(imageFileBytes); writer.Flush(); } } } catch // thrown if not found { var imagePart = mainpart.AddNewPart<ImagePart>(ExtensionText, SigId); using (BinaryWriter writer = new BinaryWriter(imagePart.GetStream())) { writer.Write(imageFileBytes); writer.Flush(); } } WP.Run para = new WP.Run( new WP.Drawing( new wp.Inline( new wp.Extent() { Cx = imageWidthEMU, Cy = imageHeightEMU }, new wp.EffectExtent() { LeftEdge = 19050L, TopEdge = 0L, RightEdge = 9525L, BottomEdge = 0L }, new wp.DocProperties() { Id = (UInt32Value)1U, Name = "Inline Text Wrapping Picture", Description = GraphicDataUri }, new wp.NonVisualGraphicFrameDrawingProperties( new a.GraphicFrameLocks() { NoChangeAspect = true }), new a.Graphic( new a.GraphicData( new pic.Picture( new pic.NonVisualPictureProperties( new pic.NonVisualDrawingProperties() { Id = (UInt32Value)0U, Name = filename }, new pic.NonVisualPictureDrawingProperties()), new pic.BlipFill( new a.Blip() { Embed = SigId }, new a.Stretch( new a.FillRectangle())), new pic.ShapeProperties( new a.Transform2D( new a.Offset() { X = 0L, Y = 0L }, new a.Extents() { Cx = imageWidthEMU, Cy = imageHeightEMU }), new a.PresetGeometry( new a.AdjustValueList() ) { Preset = a.ShapeTypeValues.Rectangle })) ) { Uri = GraphicDataUri }) ) { DistanceFromTop = (UInt32Value)0U, DistanceFromBottom = (UInt32Value)0U, DistanceFromLeft = (UInt32Value)0U, DistanceFromRight = (UInt32Value)0U })); return para; }