2021-04-17 21:52:33 +02:00
|
|
|
using System.Collections.Generic;
|
2021-02-08 14:36:12 +01:00
|
|
|
using QuestPDF.Fluent;
|
|
|
|
|
using QuestPDF.Infrastructure;
|
|
|
|
|
|
|
|
|
|
namespace QuestPDF.ReportSample.Layouts
|
|
|
|
|
{
|
|
|
|
|
public class TableOfContentsTemplate : IComponent
|
|
|
|
|
{
|
|
|
|
|
private List<ReportSection> Sections { get; }
|
|
|
|
|
|
|
|
|
|
public TableOfContentsTemplate(List<ReportSection> sections)
|
|
|
|
|
{
|
|
|
|
|
Sections = sections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Compose(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
container
|
2021-05-02 21:11:08 +02:00
|
|
|
.Decoration(decoration =>
|
2021-02-08 14:36:12 +01:00
|
|
|
{
|
2021-05-02 21:11:08 +02:00
|
|
|
decoration
|
2021-02-08 14:36:12 +01:00
|
|
|
.Header()
|
|
|
|
|
.PaddingBottom(5)
|
|
|
|
|
.Text("Table of contents", Typography.Headline);
|
|
|
|
|
|
2021-05-02 21:11:08 +02:00
|
|
|
decoration.Content().Stack(stack =>
|
2021-02-08 14:36:12 +01:00
|
|
|
{
|
|
|
|
|
stack.Spacing(5);
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < Sections.Count; i++)
|
2021-05-02 21:11:08 +02:00
|
|
|
stack.Item().Element(c => DrawLink(c, i+1, Sections[i].Title));
|
2021-02-08 14:36:12 +01:00
|
|
|
|
2021-05-02 21:11:08 +02:00
|
|
|
stack.Item().Element(c => DrawLink(c, Sections.Count+1, "Photos"));
|
2021-02-08 14:36:12 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawLink(IContainer container, int number, string locationName)
|
|
|
|
|
{
|
|
|
|
|
container
|
|
|
|
|
.InternalLink(locationName)
|
|
|
|
|
.Row(row =>
|
|
|
|
|
{
|
|
|
|
|
row.ConstantColumn(25).Text($"{number}.", Typography.Normal);
|
|
|
|
|
row.RelativeColumn().Text(locationName, Typography.Normal);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|