[]
GcWord allows you to enhance the look of shapes by customizing shape formats. As a shape represents a visual figure containing fill and outline, you can customize its fill format as well as line format. You can also add a shadow to the shape and set the shadow format.
The fill format of a shape can be customized by using FillFormat class which provides PatternFill, SolidFill, ImageFill, GradientFill properties that represent relevant fill types. The FillType enumeration can be used to define the active fill type.
To add gradient type fill format to a shape:
Add a rectangle shape to a Word document by using Add method of ShapeCollection class and pass GeometryType.Rectangle as its parameter.
Set FillType enumeration to Gradient to set gradient fill format.
Add gradient stops at different positions in the shape by using Add method of GradientStopList class.
var doc = new GcWordDocument();
var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add();
var shape = run.GetRange().Shapes.Add(300, 300, GeometryType.Rectangle);
//Set fill format to gradient
shape.Fill.Type = FillType.Gradient;
//create additional gradient stops
//position range is 0..100.
shape.Fill.GradientFill.Stops.Add(ThemeColorId.Light2, 10f);
shape.Fill.GradientFill.Stops.Add(ThemeColorId.Accent2, 70f);
shape.Fill.GradientFill.Stops.Add(ThemeColorId.Light2, 87f);
doc.Save("fillformat.docx");
The line format of a shape defines appearance of a shape's line. It can be customized by using LineFormat class and can be set to solid, gradient, image, pattern fill types. You can also set various types of line formats like dash type, cap type, join type etc. by using properties of LineFormat class.
To add solid type line format to a shape:
Add a rectangle shape to a Word document by using Add method of ShapeCollection class and pass GeometryType.Rectangle as its parameter.
Set FillType enumeration to Solid to set solid line format.
Set LineDashType and LineJoinType enumerations to set dash type and join type of line.
var doc = new GcWordDocument();
var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add();
var shape = run.GetRange().Shapes.Add(300, 300, GeometryType.Rectangle);
//Set line format to solid
shape.Line.Fill.Type = FillType.Solid;
//Set line type to dotted
shape.Line.DashType = LineDashType.Dot;
//Set line join type to round
shape.Line.JoinType = LineJoinType.Round;
doc.Save("lineformat.docx");
The shadow format adds additional depth to a shape and creates a three-dimensional effect. GcWord allows you to apply shadow format to shape using ApplyBuiltInShadow method of the ShapeEffects class that accepts BuiltInShadowId enumeration as its parameter. However, for applying custom shadow effect to a shape, you can use OuterShadow, InnerShadow or ShadowPreset type of the ShapeEffects class and set their properties.
The code below shows how to apply built-in shadow effect to a shape:
// apply lower right prospective offset shadow effect to the shape
shape.Effects.ApplyBuiltInShadow(BuiltInShadowId.ProspectiveLowerRight);
The code below shows how to apply custom shadow effect to a shape:
var canvas_shape = run.GetRange().CanvasShapes.Add(500, 500);
var shape2 = canvas_shape.GetRange().Shapes.Add(202, 250, "Shape");
shape2.Fill.SolidFill.RGB = Color.LemonChiffon;
shape2.Position.Horizontal.Offset = 4f;
var shape2InnerShadow = shape2.Effects.InnerShadow;
shape2InnerShadow.Blur = 4f;
shape2InnerShadow.Color.RGB = Color.Green;
shape2InnerShadow.Angle = 35;
shape2InnerShadow.Distance = 40f;
The blur effect makes the edges of shapes appear fuzzy or out of focus. GcWord allows you to apply blur effect to the shape by using Blur property of the ShapeEffects class. You can also apply this effect through shape styles.
// Shape Blur - direct:
Paragraph p = doc.Body.Paragraphs.Add();
Run run = p.GetRange().Runs.Add();
Shape shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star4);
shape.Fill.Type = FillType.Solid;
shape.Fill.SolidFill.RGB = Color.Yellow;
shape.Line.Width = 4;
shape.Line.Fill.SolidFill.RGB = Color.Red;
// apply 7 point blur effect to the shape
shape.Effects.Blur.Radius = 7f;
p.GetRange().Runs.Add("Shape Blur - direct.", doc.Styles[BuiltInStyleId.Strong]);
To view this sample code in action, see Blur Effect demo sample.
GcWord allows you to apply reflection format to shape using ApplyBuiltInReflection method of the ShapeEffects class that accepts BuiltInReflectionId enumeration as its parameter. You can also use styles to define and apply custom reflection effects to a shape.
The code below shows how to apply built-in reflection to a shape using the ApplyBuiltInReflection method:
// Shape reflection - direct effects:
Paragraph p = doc.Body.Paragraphs.Add();
Run run = p.GetRange().Runs.Add();
Shape shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Heptagon);
shape.Fill.Type = FillType.Solid;
shape.Fill.SolidFill.RGB = Color.PeachPuff;
shape.Line.Width = 4;
shape.Line.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
shape.Effects.ApplyBuiltInReflection(BuiltInReflectionId.TightTouching);
The code below shows how to apply custom reflection effect to a shape:
Paragraph p = doc.Body.Paragraphs.Add();
Run run = p.GetRange().Runs.Add();
var canvas_shape = run.GetRange().CanvasShapes.Add(500, 500);
var shape = canvas_shape.GetRange().Shapes.Add(202, 250, "Shape");
shape.Fill.SolidFill.RGB = Color.Red;
shape.Position.Horizontal.Offset = 4f;
var shapeCustomReflection = shape.Effects.Reflection;
shapeCustomReflection.Angle = 35;
shapeCustomReflection.Distance = 40f;
To view the code in action, see Reflection Effect demo sample.
GcWord allows you to apply glow effect to shape using ApplyBuiltInGlow method of the ShapeEffects class that accepts BuiltInGlowId enumeration as its parameter. You can also use styles to define and apply custom glow effects to a shape.
The code below shows how to apply built-in glow to a shape using the ApplyBuiltInGlow method:
var shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star5);
shape.Fill.Type = FillType.Solid;
shape.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
// apply 18 point accent 6 glow effect to the shape
shape.Effects.ApplyBuiltInGlow(BuiltInGlowId.Radius18Accent6);
p.GetRange().Runs.Add("Shape glow - direct.", doc.Styles[BuiltInStyleId.Strong]);
The code below shows how to apply custom glow effect to a shape:
var canvas_shape = run.GetRange().CanvasShapes.Add(900, 900);
var shape = canvas_shape.GetRange().Shapes.Add(102, 102, "Shape");
shape.Fill.SolidFill.RGB = Color.LemonChiffon;
shape.Position.Horizontal.Offset = 9f;
var shapeGlow = shape.Effects.Glow;
shapeGlow.Radius = 30;
shapeGlow.Color.RGB = Color.Red;
To view the code in action, see Glow Effect demo sample.
GcWord allows you to apply SoftEdge effect to the shape by using SoftEdge property of the ShapeEffects class. You can also apply this effect through shape styles.
// Shape Soft Edge - direct:
Paragraph p = doc.Body.Paragraphs.Add();
Run run = p.GetRange().Runs.Add();
Shape shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star7);
shape.Fill.Type = FillType.Solid;
shape.Fill.SolidFill.RGB = Color.Yellow;
shape.Line.Width = 8;
shape.Line.Fill.SolidFill.RGB = Color.Red;
// apply 5 point soft edge effect to the shape
shape.Effects.SoftEdge.Radius = 5f;
p.GetRange().Runs.Add("Shape Soft Edge - direct.", doc.Styles[BuiltInStyleId.Strong]);
To view this sample code in action, see SoftEdge Effect demo sample.
GcWord allows you to apply FillOverlay effect to the shape by using FillOverlay property of the ShapeEffects class. You can also apply this effect through shape styles.
// Shape fill overlay - direct:
var p = doc.Body.Paragraphs.Add();
var run = p.GetRange().Runs.Add();
var shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star8);
shape.Fill.Type = FillType.Solid;
shape.Fill.SolidFill.RGB = Color.LightBlue;
// Apply solid fill overlay with another color to mix with the main fill:
FillOverlay overlay = shape.Effects.FillOverlay;
overlay.BlendMode = BlendMode.Multiply;
overlay.Fill.Type = FillType.Solid;
overlay.Fill.SolidFill.RGB = Color.Yellow;
p.GetRange().Runs.Add("Shape fill overlay - direct.", doc.Styles[BuiltInStyleId.Strong]);
To view this sample code in action, see FillOverlay Effect demo sample.
The 3D effects refer to the effects applied in three spatial dimensions: width, height, and depth. The 3D effects give the shape a unique and artistic look. For applying 3D effects, GcWord provides the ThreeDFormat and ThreeDScene classes and the ApplyEffectsPreset method. The ApplyEffectsPreset method allows a user to add preset 3D effects. However, the ThreeDFormat and ThreeDScene classes allow a user to add custom 3D effects.
Preset 3D Effect
Custom 3D Effect
3D Rotation
Refer to the following example code to add a preset 3D effect:
// Initialize GcWordDocument.
GcWordDocument doc = new GcWordDocument();
// Add a shape to the document.
Paragraph paragraph = doc.Body.Paragraphs.Add();
Run run = paragraph.GetRange().Runs.Add();
Shape shape = run.GetRange().Shapes.Add(200, 200, GeometryType.Rectangle);
shape.Fill.Type = FillType.Solid;
shape.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
// Apply a preset 3D shape effect.
shape.ApplyEffectsPreset(ShapeEffectsPreset.Preset10);
// Save the Word document.
doc.Save("Preset3DEffects.docx");
Refer to the following example code to add a custom 3D effect:
// Initialize GcWordDocument.
GcWordDocument doc = new GcWordDocument();
// Add a shape to the document.
Paragraph paragraph = doc.Body.Paragraphs.Add();
Run run = paragraph.GetRange().Runs.Add();
var shape = run.GetRange().Shapes.Add(200, 200, GeometryType.Rectangle);
shape.Fill.Type = FillType.Solid;
shape.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
// Apply 3D format to the shape.
ThreeDFormat threeD = shape.Effects.ThreeDFormat;
threeD.TopBevel.ApplyPreset(BevelType.Convex);
threeD.Contour.Color.ThemeColor = ThemeColorId.Accent2;
threeD.Contour.Width = 3f;
threeD.Contour.Color.ThemeColor = ThemeColorId.Accent6;
threeD.Contour.Width = 12f;
// Apply 3D scene to the shape.
ThreeDScene scene = shape.Effects.ThreeDScene;
scene.Camera.Preset = CameraPreset.PerspectiveContrastingRightFacing;
scene.Lighting.Type = LightRigType.BrightRoom;
scene.Lighting.Rotation.Latitude = 90f;
scene.Lighting.Rotation.Revolution = 5f;
// Save the Word document.
doc.Save("3DEffects.docx");
Refer to the following example code to add a 3D rotation effect:
// Initialize GcWordDocument.
GcWordDocument doc = new GcWordDocument();
// Add a shape to the document.
Paragraph paragraph = doc.Body.Paragraphs.Add();
Run run = paragraph.GetRange().Runs.Add();
Shape shape = run.GetRange().Shapes.Add(200, 200, GeometryType.Rectangle);
shape.Fill.Type = FillType.Solid;
shape.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
shape.Line.Fill.Type = FillType.NoFill;
// Add outershadow to the shape.
OuterShadow shadow = shape.Effects.Shadow;
shadow.Alignment = RectangleAlignment.Center;
shadow.Angle = 87f;
shadow.Blur = 17.75f;
shadow.Distance = 4f;
shadow.Color.RGB = Color.FromArgb(255, 0, 0, 0);
shadow.Color.Transparency = 0.67f;
// Apply 3D format.
ThreeDFormat threeDFormat = shape.Effects.ThreeDFormat;
threeDFormat.Depth.Width = 20f;
threeDFormat.Contour.Width = 1.5f;
threeDFormat.Contour.Color.RGB = Color.FromArgb(255, 255, 255, 255);
// Add top bevel.
Bevel topbevel = threeDFormat.TopBevel;
topbevel.Type = BevelType.Angle;
topbevel.Width = 6.5f;
topbevel.Height = 3.5f;
// Add bottom bevel.
Bevel bottomBevel = threeDFormat.BottomBevel;
bottomBevel.Type = BevelType.Angle;
bottomBevel.Width = 6.5f;
bottomBevel.Height = 3.5f;
// Apply 3D scene.
Lighting lighting = shape.Effects.ThreeDScene.Lighting;
lighting.Type = LightRigType.Harsh;
lighting.Direction = LightRigDirection.Top;
lighting.Rotation.Latitude = 0f;
lighting.Rotation.Longitude = 0f;
lighting.Rotation.Revolution = 50f;
// Apply rotation to the shape.
Camera camera = shape.Effects.ThreeDScene.Camera;
camera.Preset = CameraPreset.PerspectiveFront;
camera.Perspective = 55f;
camera.Rotation.Latitude = 8.1f;
camera.Rotation.Longitude = 325.5f;
camera.Rotation.Revolution = 2.9f;
// Save the Word document.
doc.Save("Shape3DRotation.docx");
Limitation
GcWord does not support the export of 3D effects to PDF or images.