[]
        
(Showing Draft Content)

Canvas Shape

A canvas shape acts as a container for multiple drawing objects and can be used to organize them all at once.

GcWord allows you to draw a canvas shape and add multiple drawing objects to it. A canvas shape can be added by using Add and Insert methods of CanvasShapeCollection class. You can also access the previous or next canvas shapes and apply fill format or line format properties on them by using various methods provided by CanvasShape class.

Add Canvas Shape

To add canvas shape 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 canvas shape by using Add method of CanvasShapeCollection class.

  4. Add two shapes inside canvas shape by using Add method of ShapeCollection class.

  5. Move the horizontal and vertical position of second shape by using Offset property of ShapeHorizontalPosition class so that it does not overlap the first shape.

    var doc = new GcWordDocument();
    
    //Add Run element       
    var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add();
    
    //Create canvas shape with initial width 500 and height 500
    var canvas_shape = run.GetRange().CanvasShapes.Add(500, 500);
    
    //Create two shapes inside canvas shape
    var firstShape = canvas_shape.GetRange().Shapes.Add(202, 250, "First shape");
    var secondshape = canvas_shape.GetRange().Shapes.Add(300, 400, "Second shape");
    
    //Move second shape 100 points right and 100 points lower
    secondshape.Position.Horizontal.Offset = 100;
    secondshape.Position.Vertical.Offset = 100;
    
    //Save document
    doc.Save("CanvasShape.docx");

Delete Canvas Shape

To delete canvas shape in a document:

  1. Load the document containing canvas shape using Load method of GcWordDocument class.

  2. Delete the canvas shape by using Delete method of ContentObject class.

    //Load document
    doc.Load("CanvasShape.docx");
    
    //Access first canvas
    CanvasShape cs = doc.Body.CanvasShapes.First;
    //Delete canvas
    cs.Delete();
    
    doc.Save("CanvasDelete.docx");

Limitations

  • Unsupported Properties: NonVisualGroupDrawingShapePropsExtensionList, GroupShapeLocks, OfficeArtExtensionList, Scene3DType, ShapePropertiesExtensionList

  • Unsupported Effects and derived classes: EffectsDAG,EffectsList, WholeFormattingEffectList, WholeFormattingEffectDag