i've been trying something new to me, i need to insert images from a stream but everytime i try to insert an image it corrupts the word document, i am using office 2010.
i have the following code adding the images to the word document
private void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId, string documentName)
{
var element = new Drawing(new DW.Inline(new DW.Extent { Cx = 990000L, Cy = 792000L }, new DW.EffectExtent
{
LeftEdge = 0L,
TopEdge = 0L,
RightEdge = 0L,
BottomEdge = 0L
},
new DW.DocProperties
{
Id = (UInt32Value)1U,
Name = "Picture 1"
}, new DW.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 = documentName
}, new PIC.NonVisualPictureDrawingProperties()), new PIC.BlipFill(new A.Blip
{
Embed = relationshipId,
CompressionState =
A.BlipCompressionValues.Print
}, new A.Stretch(new A.FillRectangle())), new PIC.ShapeProperties(new A.Transform2D(new A.Offset { X = 0L, Y = 0L }, new A.Extents { Cx = 990000L, Cy = 792000L }), new A.PresetGeometry(
new A.AdjustValueList()) { Preset = A.ShapeTypeValues.Rectangle })))))
{
DistanceFromTop = (UInt32Value)0U,
DistanceFromBottom = (UInt32Value)0U,
DistanceFromLeft = (UInt32Value)0U,
DistanceFromRight = (UInt32Value)0U
});
wordDoc.MainDocumentPart.Document.Body.AppendChild(new Run(element));
}
Thanks Quandary
but that didn't help as well, so i am saving the images to a folder and using the AddPicture Method in Interop
Why don't you use the docx library ?
3) DocX also supports
a) Pictures,
Like this: http://cathalscorner.blogspot.com/2009/04/docx-version-1002-released.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.