InlinedExamples.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Linq;
  3. using System.Reflection.Metadata.Ecma335;
  4. using NUnit.Framework;
  5. using QuestPDF.Examples.Engine;
  6. using QuestPDF.Fluent;
  7. using QuestPDF.Helpers;
  8. using QuestPDF.Infrastructure;
  9. namespace QuestPDF.Examples
  10. {
  11. public class InlinedExamples
  12. {
  13. [Test]
  14. public void Inlined()
  15. {
  16. RenderingTest
  17. .Create()
  18. .PageSize(800, 650)
  19. .ProduceImages()
  20. .ShowResults()
  21. .Render(container =>
  22. {
  23. container
  24. .Padding(25)
  25. .Decoration(decoration =>
  26. {
  27. decoration.Before().Text(text =>
  28. {
  29. text.DefaultTextStyle(TextStyle.Default.Size(20));
  30. text.CurrentPageNumber();
  31. text.Span(" / ");
  32. text.TotalPages();
  33. });
  34. decoration
  35. .Content()
  36. .PaddingTop(25)
  37. //.MinimalBox()
  38. .Border(1)
  39. .Background(Colors.Grey.Lighten2)
  40. .Inlined(inlined =>
  41. {
  42. inlined.Spacing(25);
  43. inlined.AlignSpaceAround();
  44. inlined.BaselineMiddle();
  45. var random = new Random(123);
  46. foreach (var _ in Enumerable.Range(0, 50))
  47. {
  48. var width = random.Next(2, 7);
  49. var height = random.Next(2, 7);
  50. var sizeText = $"{width}×{height}";
  51. inlined
  52. .Item()
  53. .Border(1)
  54. .Width(width * 25)
  55. .Height(height * 25)
  56. .Background(Placeholders.BackgroundColor())
  57. .Layers(layers =>
  58. {
  59. layers.Layer().Grid(grid =>
  60. {
  61. grid.Columns(width);
  62. Enumerable.Range(0, width * height).ToList().ForEach(x => grid.Item().Border(1).BorderColor(Colors.White).Width(25).Height(25));
  63. });
  64. layers
  65. .PrimaryLayer()
  66. .AlignCenter()
  67. .AlignMiddle()
  68. .Text(sizeText)
  69. .FontSize(15);
  70. });
  71. }
  72. });
  73. });
  74. });
  75. }
  76. [Test]
  77. public void Inline_AlignLeft_BaselineBottom()
  78. {
  79. RenderingTest
  80. .Create()
  81. .PageSize(800, 600)
  82. .ProduceImages()
  83. .ShowResults()
  84. .Render(container =>
  85. {
  86. container
  87. .Padding(20)
  88. .MinimalBox()
  89. .Border(1)
  90. .Background(Colors.Grey.Lighten4)
  91. .Inlined(inlined =>
  92. {
  93. inlined.VerticalSpacing(50);
  94. inlined.HorizontalSpacing(25);
  95. inlined.AlignRight();
  96. inlined.BaselineMiddle();
  97. foreach (var _ in Enumerable.Range(0, 100))
  98. inlined.Item().Element(RandomBlock);
  99. });
  100. });
  101. void RandomBlock(IContainer container)
  102. {
  103. container
  104. .Width(Placeholders.Random.Next(1, 5) * 20)
  105. .Height(Placeholders.Random.Next(1, 5) * 20)
  106. .Border(1)
  107. .BorderColor(Colors.Grey.Darken2)
  108. .Background(Placeholders.BackgroundColor());
  109. }
  110. }
  111. [Test]
  112. public void RepeatingInlinedInHeader_Test()
  113. {
  114. RenderingTest
  115. .Create()
  116. .ProduceImages()
  117. .ShowResults()
  118. .RenderDocument(document =>
  119. {
  120. document.Page(page =>
  121. {
  122. page.Size(PageSizes.A4);
  123. page.Margin(1, Unit.Inch);
  124. page.PageColor(Colors.White);
  125. page.Header()
  126. .Inlined(inlined =>
  127. {
  128. inlined.Spacing(10);
  129. foreach (var i in Enumerable.Range(5, 5))
  130. inlined.Item().Width(i * 10).Height(20).Background(Colors.Red.Medium);
  131. });
  132. page.Content()
  133. .PaddingVertical(20)
  134. .Column(column =>
  135. {
  136. column.Spacing(25);
  137. foreach (var i in Enumerable.Range(10, 20))
  138. column.Item().Width(i * 10).Height(50).Background(Colors.Grey.Lighten2);
  139. });
  140. });
  141. });
  142. }
  143. }
  144. }