LazyExamples.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples;
  5. public class LazyExamples
  6. {
  7. class SimpleComponent : IComponent
  8. {
  9. public required int Start { get; init; }
  10. public required int End { get; init; }
  11. public void Compose(IContainer container)
  12. {
  13. container.Decoration(decoration =>
  14. {
  15. decoration.Before()
  16. .Text($"Numbers from {Start} to {End}")
  17. .FontSize(20).Bold().FontColor(Colors.Blue.Darken2);
  18. decoration.Content().Column(column =>
  19. {
  20. foreach (var i in Enumerable.Range(Start, End - Start + 1))
  21. column.Item().Text($"Number {i}").FontSize(10);
  22. });
  23. });
  24. }
  25. }
  26. [Test]
  27. [Ignore("This test is for manual testing only.")]
  28. public void Disabled()
  29. {
  30. Document
  31. .Create(document =>
  32. {
  33. document.Page(page =>
  34. {
  35. page.Margin(10);
  36. page.Content().Column(column =>
  37. {
  38. const int sectionSize = 1000;
  39. foreach (var i in Enumerable.Range(0, 1000))
  40. {
  41. column.Item().Component(new SimpleComponent
  42. {
  43. Start = i * sectionSize,
  44. End = i * sectionSize + sectionSize - 1
  45. });
  46. }
  47. });
  48. });
  49. })
  50. .GeneratePdf("lazy-disabled.pdf");
  51. }
  52. [Test]
  53. [Ignore("This test is for manual testing only.")]
  54. public void Enabled()
  55. {
  56. Document
  57. .Create(document =>
  58. {
  59. document.Page(page =>
  60. {
  61. page.Margin(10);
  62. page.Content().Column(column =>
  63. {
  64. const int sectionSize = 1000;
  65. foreach (var i in Enumerable.Range(0, 1000))
  66. {
  67. var start = i * sectionSize;
  68. var end = start + sectionSize - 1;
  69. column.Item().Lazy(c =>
  70. {
  71. c.Component(new SimpleComponent
  72. {
  73. Start = start,
  74. End = end
  75. });
  76. });
  77. }
  78. });
  79. });
  80. })
  81. .GeneratePdf("lazy-enabled.pdf");
  82. }
  83. [Test]
  84. [Ignore("This test is for manual testing only.")]
  85. public void EnabledWithCache()
  86. {
  87. Document
  88. .Create(document =>
  89. {
  90. document.Page(page =>
  91. {
  92. page.Margin(10);
  93. page.Content().Column(column =>
  94. {
  95. const int sectionSize = 1000;
  96. foreach (var i in Enumerable.Range(0, 1000))
  97. {
  98. var start = i * sectionSize;
  99. var end = start + sectionSize - 1;
  100. column.Item().LazyWithCache(c =>
  101. {
  102. c.Component(new SimpleComponent
  103. {
  104. Start = start,
  105. End = end
  106. });
  107. });
  108. }
  109. });
  110. });
  111. })
  112. .GeneratePdf("lazy-enabled-with-cache.pdf");
  113. }
  114. }