ShadowEffect.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using GrapeCity.Documents.Word;
  11.  
  12. namespace DsWordWeb.Demos
  13. {
  14. // This example shows how to add shadow effect to text and shapes in a DOCX.
  15. public class ShadowEffect
  16. {
  17. public GcWordDocument CreateDocx()
  18. {
  19. var doc = new GcWordDocument();
  20.  
  21. // Create paragraph styling:
  22. var style = doc.Styles.Add("My Style", StyleType.Paragraph);
  23. style.Font.Size = 48;
  24. style.Font.Name = "Lucida";
  25. style.Font.Bold = true;
  26. style.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  27.  
  28. // Create top right offset shadow effect for paragraph text:
  29. OuterShadow shadow = style.Font.Effects.Shadow;
  30. shadow.Alignment = RectangleAlignment.BottomLeft;
  31. shadow.Angle = 250f;
  32. shadow.Blur = 3f;
  33. shadow.Distance = 10f;
  34. shadow.ScaleX = 100f;
  35. shadow.ScaleY = 50f;
  36. shadow.SkewX = -30f;
  37. shadow.SkewY = 0f;
  38. shadow.Color.RGB = Color.Gray;
  39. shadow.Color.Transparency = 0.3f;
  40.  
  41. // Apply top right offset shadow effect to the text:
  42. doc.Body.Paragraphs.Add("\n TREADSTONE", style);
  43.  
  44. // Add a shape to the document:
  45. var para = doc.Body.Paragraphs.Add("\n \n \n");
  46. para.Format.Alignment = ParagraphAlignment.Center;
  47. var run = para.GetRange().Runs.Add();
  48. var shape = run.GetRange().Shapes.Add(450, 100, GeometryType.HorizontalScroll);
  49. shape.Fill.SolidFill.RGB = Color.SteelBlue;
  50.  
  51. // Append text to the shape:
  52. var txtstyle = doc.Styles.Add("Text Style", StyleType.Paragraph);
  53. txtstyle.Font.Size = 28;
  54. txtstyle.Font.Bold = true;
  55. txtstyle.Font.Color.RGB = Color.White;
  56. txtstyle.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  57. TextFrame frame = shape.AddTextFrame("FINANCIAL REPORT \n 2021-2022", txtstyle);
  58.  
  59. // Apply built-in shadow effect to the shape:
  60. shape.Effects.ApplyBuiltInShadow(BuiltInShadowId.ProspectiveLowerLeft);
  61.  
  62. // Done:
  63. return doc;
  64. }
  65. }
  66. }
  67.