InlinedExamples.cs 6.3 KB

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