ColumnExamples.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 ColumnExamples
  11. {
  12. [Test]
  13. public void Column()
  14. {
  15. RenderingTest
  16. .Create()
  17. .PageSize(PageSizes.A4)
  18. .ShowResults()
  19. .ProducePdf()
  20. .Render(container =>
  21. {
  22. container.Column(column =>
  23. {
  24. foreach (var i in Enumerable.Range(0, 10))
  25. column.Item().Element(Block);
  26. static void Block(IContainer container)
  27. {
  28. container
  29. .Width(72)
  30. .Height(3.5f, Unit.Inch)
  31. .Height(1.5f, Unit.Inch)
  32. .Background(Placeholders.BackgroundColor());
  33. }
  34. });
  35. });
  36. }
  37. [Test]
  38. public void Stability_NoItems()
  39. {
  40. RenderingTest
  41. .Create()
  42. .ProducePdf()
  43. .MaxPages(100)
  44. .PageSize(250, 150)
  45. .Render(container =>
  46. {
  47. container
  48. .Padding(25)
  49. .Column(column => { });
  50. });
  51. }
  52. [Test]
  53. public void MultiColumn()
  54. {
  55. RenderingTest
  56. .Create()
  57. .ProducePdf()
  58. .ShowResults()
  59. .EnableDebugging()
  60. .PageSize(PageSizes.A4)
  61. .MaxPages(100)
  62. .Render(container =>
  63. {
  64. container
  65. .Padding(20)
  66. .MultiColumn(content =>
  67. {
  68. content.Spacing(20);
  69. foreach (var i in Enumerable.Range(1, 70))
  70. {
  71. content
  72. .Item()
  73. .Width(150 + (float)Math.Sin(i * 2 * Math.PI / 10) * 50)
  74. .Height(40)
  75. .Border(1)
  76. .Background(Colors.Grey.Lighten4)
  77. .AlignCenter()
  78. .AlignMiddle()
  79. .Text(i.ToString());
  80. }
  81. });
  82. });
  83. }
  84. }
  85. }