TableWithFooterTests.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.Table;
  7. internal class TableWithFooterTests : 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. .Shrink()
  19. .Border(1)
  20. .BorderColor(Colors.Grey.Darken1)
  21. .SemanticTable()
  22. .Table(table =>
  23. {
  24. table.ColumnsDefinition(columns =>
  25. {
  26. columns.RelativeColumn();
  27. columns.RelativeColumn();
  28. columns.RelativeColumn();
  29. });
  30. foreach (var i in Enumerable.Range(1, 30))
  31. {
  32. table.Cell().Element(CellStyle).Text($"{i}/1");
  33. table.Cell().Element(CellStyle).Text($"{i}/2");
  34. table.Cell().Element(CellStyle).Text($"{i}/3");
  35. }
  36. table.Footer(footer =>
  37. {
  38. footer.Cell().Element(FooterCellStyle).Text("F11");
  39. footer.Cell().Element(FooterCellStyle).Text("F12");
  40. footer.Cell().Element(FooterCellStyle).Text("F13");
  41. footer.Cell().Element(FooterCellStyle).Text("F21");
  42. footer.Cell().Element(FooterCellStyle).Text("F22");
  43. footer.Cell().Element(FooterCellStyle).Text("F23");
  44. });
  45. IContainer CellStyle(IContainer container) =>
  46. container
  47. .Border(1)
  48. .BorderColor(Colors.Grey.Lighten2)
  49. .Padding(8);
  50. IContainer FooterCellStyle(IContainer container) =>
  51. container
  52. .Border(1)
  53. .BorderColor(Colors.Grey.Lighten2)
  54. .Background(Colors.Grey.Lighten3)
  55. .Padding(8);
  56. });
  57. });
  58. });
  59. }
  60. protected override SemanticTreeNode? GetExpectedSemanticTree()
  61. {
  62. return ExpectedSemanticTree.DocumentRoot(root =>
  63. {
  64. root.Child("Table", table =>
  65. {
  66. table.Child("TBody", tbody =>
  67. {
  68. foreach (var i in Enumerable.Range(1, 30))
  69. {
  70. tbody.Child("TR", row =>
  71. {
  72. row.Child("TD", td => td.Child("P"));
  73. row.Child("TD", td => td.Child("P"));
  74. row.Child("TD", td => td.Child("P"));
  75. });
  76. }
  77. });
  78. table.Child("TFoot", footer =>
  79. {
  80. footer.Child("TR", tfoot =>
  81. {
  82. tfoot.Child("TR", row =>
  83. {
  84. row.Child("TD", td => td.Child("P"));
  85. row.Child("TD", td => td.Child("P"));
  86. row.Child("TD", td => td.Child("P"));
  87. });
  88. tfoot.Child("TR", row =>
  89. {
  90. row.Child("TD", td => td.Child("P"));
  91. row.Child("TD", td => td.Child("P"));
  92. row.Child("TD", td => td.Child("P"));
  93. });
  94. });
  95. });
  96. });
  97. });
  98. }
  99. }