TableOfContentsTemplate.cs 1.7 KB

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