ColumnExamples.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples;
  5. public class ColumnExamples
  6. {
  7. [Test]
  8. public void SimpleExample()
  9. {
  10. Document
  11. .Create(document =>
  12. {
  13. document.Page(page =>
  14. {
  15. page.MinSize(new PageSize(250, 0));
  16. page.MaxSize(new PageSize(250, 1000));
  17. page.Margin(25);
  18. page.Content()
  19. .Column(column =>
  20. {
  21. column.Item().Background(Colors.Grey.Medium).Height(50);
  22. column.Item().Background(Colors.Grey.Lighten1).Height(75);
  23. column.Item().Background(Colors.Grey.Lighten2).Height(100);
  24. });
  25. });
  26. })
  27. .GenerateImages(x => "column-simple.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  28. }
  29. [Test]
  30. public void SpacingExample()
  31. {
  32. Document
  33. .Create(document =>
  34. {
  35. document.Page(page =>
  36. {
  37. page.MinSize(new PageSize(250, 0));
  38. page.MaxSize(new PageSize(250, 1000));
  39. page.Margin(25);
  40. page.Content()
  41. .Column(column =>
  42. {
  43. column.Spacing(25);
  44. column.Item().Background(Colors.Grey.Medium).Height(50);
  45. column.Item().Background(Colors.Grey.Lighten1).Height(75);
  46. column.Item().Background(Colors.Grey.Lighten2).Height(100);
  47. });
  48. });
  49. })
  50. .GenerateImages(x => "column-spacing.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  51. }
  52. [Test]
  53. public void CustomSpacingExample()
  54. {
  55. Document
  56. .Create(document =>
  57. {
  58. document.Page(page =>
  59. {
  60. page.MinSize(new PageSize(250, 0));
  61. page.MaxSize(new PageSize(250, 1000));
  62. page.Margin(25);
  63. page.Content()
  64. .Column(column =>
  65. {
  66. column.Item().Background(Colors.Grey.Darken1).Height(50);
  67. column.Item().Height(10);
  68. column.Item().Background(Colors.Grey.Medium).Height(50);
  69. column.Item().Height(20);
  70. column.Item().Background(Colors.Grey.Lighten1).Height(50);
  71. column.Item().Height(30);
  72. column.Item().Background(Colors.Grey.Lighten2).Height(50);
  73. });
  74. });
  75. })
  76. .GenerateImages(x => "column-spacing-custom.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  77. }
  78. [Test]
  79. public void DisableUniformItemsWidthExample()
  80. {
  81. Document
  82. .Create(document =>
  83. {
  84. document.Page(page =>
  85. {
  86. page.MinSize(new PageSize(400, 0));
  87. page.MaxSize(new PageSize(400, 1000));
  88. page.DefaultTextStyle(x => x.FontSize(20));
  89. page.Margin(25);
  90. page.PageColor(Colors.White);
  91. page.Content()
  92. .Column(column =>
  93. {
  94. column.Spacing(15);
  95. column.Item()
  96. .Element(LabelStyle)
  97. .Text("REST API");
  98. column.Item()
  99. .Element(LabelStyle)
  100. .Text("Garbage Collection");
  101. column.Item()
  102. .Element(LabelStyle)
  103. .Text("Object-Oriented Programming");
  104. static IContainer LabelStyle(IContainer container) => container
  105. .ShrinkHorizontal()
  106. .Background(Colors.Grey.Lighten3)
  107. .CornerRadius(15)
  108. .Padding(15);
  109. });
  110. });
  111. })
  112. .GenerateImages(x => "column-uniform-width-disabled.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  113. }
  114. }