TableOfContentsTemplate.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.ReportSample.Layouts
  7. {
  8. public class TableOfContentsTemplate : IComponent
  9. {
  10. private List<ReportSection> Sections { get; }
  11. public TableOfContentsTemplate(List<ReportSection> sections)
  12. {
  13. Sections = sections;
  14. }
  15. public void Compose(IContainer container)
  16. {
  17. container
  18. .Section(section =>
  19. {
  20. section
  21. .Header()
  22. .PaddingBottom(5)
  23. .Text("Table of contents", Typography.Headline);
  24. section.Content().PageableStack(stack =>
  25. {
  26. stack.Spacing(5);
  27. for (var i = 0; i < Sections.Count; i++)
  28. stack.Element(c => DrawLink(c, i+1, Sections[i].Title));
  29. stack.Element(c => DrawLink(c, Sections.Count+1, "Photos"));
  30. });
  31. });
  32. }
  33. private void DrawLink(IContainer container, int number, string locationName)
  34. {
  35. container
  36. .InternalLink(locationName)
  37. .Row(row =>
  38. {
  39. row.ConstantColumn(25).Text($"{number}.", Typography.Normal);
  40. row.RelativeColumn().Text(locationName, Typography.Normal);
  41. });
  42. }
  43. }
  44. }