TableOfContentsTests.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using QuestPDF.ConformanceTests.TestEngine;
  2. using QuestPDF.Drawing;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.ConformanceTests;
  7. internal class TableOfContentsTests : ConformanceTestBase
  8. {
  9. protected override Document GetDocumentUnderTest()
  10. {
  11. return Document
  12. .Create(document =>
  13. {
  14. document.Page(page =>
  15. {
  16. page.Margin(60);
  17. page.Content()
  18. .PaddingVertical(30)
  19. .Column(column =>
  20. {
  21. column.Item()
  22. .ExtendVertical()
  23. .AlignMiddle()
  24. .SemanticHeader1()
  25. .Text("Conformance Test:\nTable of Contents")
  26. .FontSize(36)
  27. .Bold()
  28. .FontColor(Colors.Blue.Darken2);
  29. column.Item().PageBreak();
  30. column.Item().Element(GenerateTableOfContentsSection);
  31. column.Item().PageBreak();
  32. column.Item().Element(GeneratePlaceholderContentSection);
  33. });
  34. });
  35. })
  36. .WithMetadata(new DocumentMetadata
  37. {
  38. Language = "en-US",
  39. Title = "Conformance Test",
  40. Subject = "Table of Contents"
  41. });
  42. }
  43. protected override SemanticTreeNode? GetExpectedSemanticTree()
  44. {
  45. throw new NotImplementedException();
  46. }
  47. private void GenerateTableOfContentsSection(IContainer container)
  48. {
  49. container
  50. .SemanticSection()
  51. .Column(column =>
  52. {
  53. column.Spacing(15);
  54. column
  55. .Item()
  56. .Text("Table of Contents")
  57. .Bold()
  58. .FontSize(20)
  59. .FontColor(Colors.Blue.Medium);
  60. column.Item()
  61. .SemanticTableOfContents()
  62. .Column(column =>
  63. {
  64. column.Spacing(5);
  65. foreach (var i in Enumerable.Range(1, 10))
  66. {
  67. column.Item()
  68. .SemanticTableOfContentsItem()
  69. .SemanticLink($"Link to section {i}")
  70. .SectionLink($"section-{i}")
  71. .Row(row =>
  72. {
  73. row.ConstantItem(25).Text($"{i}.");
  74. row.AutoItem().Text(Placeholders.Label());
  75. row.RelativeItem().PaddingHorizontal(2).TranslateY(11).LineHorizontal(1).LineDashPattern([1, 3]);
  76. row.AutoItem().Text(text => text.BeginPageNumberOfSection($"section-{i}"));
  77. });
  78. }
  79. });
  80. });
  81. }
  82. private void GeneratePlaceholderContentSection(IContainer container)
  83. {
  84. container
  85. .Column(column =>
  86. {
  87. foreach (var i in Enumerable.Range(1, 10))
  88. {
  89. column.Item()
  90. .SemanticSection()
  91. .Section($"section-{i}")
  92. .Column(column =>
  93. {
  94. column.Spacing(15);
  95. column.Item()
  96. .SemanticHeader2()
  97. .Text($"Section {i}")
  98. .Bold()
  99. .FontSize(20)
  100. .FontColor(Colors.Blue.Medium);
  101. column.Item().Text(Placeholders.Paragraph());
  102. foreach (var j in Enumerable.Range(1, i))
  103. {
  104. column.Item()
  105. .ArtifactOther()
  106. .Width(200)
  107. .Height(150)
  108. .CornerRadius(10)
  109. .Background(Placeholders.BackgroundColor());
  110. }
  111. });
  112. if (i < 10)
  113. column.Item().PageBreak();
  114. }
  115. });
  116. }
  117. }