AlignmentExtensions.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using QuestPDF.Elements;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.Fluent
  5. {
  6. public static class AlignmentExtensions
  7. {
  8. private static IContainer Alignment(this IContainer element, Action<Alignment> handler)
  9. {
  10. var alignment = element as Alignment ?? new Alignment();
  11. handler(alignment);
  12. return element.Element(alignment);
  13. }
  14. /// <summary>
  15. /// Aligns content horizontally to the left side.
  16. /// <a href="https://www.questpdf.com/api-reference/alignment.html">Learn more</a>
  17. /// </summary>
  18. public static IContainer AlignLeft(this IContainer element)
  19. {
  20. return element.Alignment(x => x.Horizontal = HorizontalAlignment.Left);
  21. }
  22. /// <summary>
  23. /// Aligns content horizontally to the center, ensuring equal space on both left and right sides.
  24. /// <a href="https://www.questpdf.com/api-reference/alignment.html">Learn more</a>
  25. /// </summary>
  26. public static IContainer AlignCenter(this IContainer element)
  27. {
  28. return element.Alignment(x => x.Horizontal = HorizontalAlignment.Center);
  29. }
  30. /// <summary>
  31. /// Aligns its content horizontally to the right side.
  32. /// <a href="https://www.questpdf.com/api-reference/alignment.html">Learn more</a>
  33. /// </summary>
  34. public static IContainer AlignRight(this IContainer element)
  35. {
  36. return element.Alignment(x => x.Horizontal = HorizontalAlignment.Right);
  37. }
  38. /// <summary>
  39. /// Aligns content vertically to the upper side.
  40. /// <a href="https://www.questpdf.com/api-reference/alignment.html">Learn more</a>
  41. /// </summary>
  42. public static IContainer AlignTop(this IContainer element)
  43. {
  44. return element.Alignment(x => x.Vertical = VerticalAlignment.Top);
  45. }
  46. /// <summary>
  47. /// Aligns content vertically to the center, ensuring equal space above and below.
  48. /// <a href="https://www.questpdf.com/api-reference/alignment.html">Learn more</a>
  49. /// </summary>
  50. public static IContainer AlignMiddle(this IContainer element)
  51. {
  52. return element.Alignment(x => x.Vertical = VerticalAlignment.Middle);
  53. }
  54. /// <summary>
  55. /// Aligns content vertically to the bottom side.
  56. /// <a href="https://www.questpdf.com/api-reference/alignment.html">Learn more</a>
  57. /// </summary>
  58. public static IContainer AlignBottom(this IContainer element)
  59. {
  60. return element.Alignment(x => x.Vertical = VerticalAlignment.Bottom);
  61. }
  62. }
  63. }