Documents for Word .NET Edition
Features / Shapes / Picture
In This Topic
    Picture
    In This Topic

    GcWord 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:

    1. Create a new Word document by instantiating GcWordDocument class.
    2. Add a run to a newly added paragraph by using Add method of RunCollection class.
    3. Add a picture by using Add method of PictureCollection class.
    4. Set the position, width and outline color of picture by using various properties.
      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");
    Back to Top

    Limitations

    Effects and derived classes (EffectsDAG, EffectsList) are not supported.