ComplexGraphicsWithSvgExamples.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using NUnit.Framework;
  3. using QuestPDF.Examples.Engine;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.Examples;
  7. public class ComplexGraphicsWithSvgExamples
  8. {
  9. [Test]
  10. public void ComplexBorder()
  11. {
  12. RenderingTest
  13. .Create()
  14. .PageSize(300, 200)
  15. .ProduceImages()
  16. .ShowResults()
  17. .Render(container =>
  18. {
  19. container
  20. .Padding(25)
  21. .DashedBorder(content =>
  22. {
  23. content
  24. .AlignCenter()
  25. .AlignMiddle()
  26. .Text("Text")
  27. .FontSize(30);
  28. });
  29. });
  30. }
  31. }
  32. public static class ComplexBorderExtensions
  33. {
  34. public static void DashedBorder(this IContainer container, Action<IContainer> content)
  35. {
  36. container.Layers(layers =>
  37. {
  38. layers.Layer().Svg(size =>
  39. {
  40. return $"""
  41. <svg width="{size.Width}" height="{size.Height}" xmlns="http://www.w3.org/2000/svg">
  42. <rect x="0" y="0" width="{size.Width}" height="{size.Height}" rx="20" ry="20" style="stroke:black; stroke-width:5; stroke-dasharray:5,5,10,5; fill:#AACCEE;" />
  43. </svg>
  44. """;
  45. });
  46. layers.PrimaryLayer()
  47. .AlignCenter()
  48. .AlignMiddle()
  49. .Text("Text")
  50. .FontSize(30);
  51. });
  52. }
  53. }