DsWord allows you to add pictures in documents and apply various settings on them. A picture can be added by using Add and Insert methods of PictureCollection class. You can also access the previous or next pictures, apply fill format, line format, shape style, set alternative text, title etc. by using methods provided by Picture class.
To add picture in a document:
C# |
Copy Code |
---|---|
var doc = new GcWordDocument(); //Create run element var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add(); //Add a picture var pic = run.GetRange().Pictures.Add(); pic.ImageData.SetImage(new Uri("Resources/picture.png"), "image/png"); //Shift picture position 100 points lower pic.Position.Vertical.RelativeTo = ShapeVerticalRelativePosition.Page; pic.Position.Vertical.Offset = 100; //Set outline width pic.Line.Width = 2; //Increase "effective size" of shape by same value as outline width pic.Size.EffectExtent.AllEdges = 2; //set outline color pic.Line.Fill.Type = FillType.Solid; pic.Line.Fill.SolidFill.RGB = System.Drawing.Color.Red; doc.Save("Picture.docx"); |
Limitations
Effects and derived classes (EffectsDAG, EffectsList) are not supported.