Files

63 lines
2.2 KiB
C#
Raw Permalink Normal View History

2021-04-17 21:52:33 +02:00
using System.Collections.Generic;
2022-02-16 15:34:54 +01:00
using System.Drawing;
using QuestPDF.Fluent;
2022-02-16 15:34:54 +01:00
using QuestPDF.Helpers;
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
.Decoration(decoration =>
{
decoration
2022-01-16 17:08:57 +01:00
.Before()
.PaddingBottom(5)
.Text("Table of contents", Typography.Headline);
decoration.Content().Column(column =>
{
column.Spacing(5);
for (var i = 0; i < Sections.Count; i++)
column.Item().Element(c => DrawLink(c, i+1, Sections[i].Title));
column.Item().Element(c => DrawLink(c, Sections.Count+1, "Photos"));
});
});
}
private void DrawLink(IContainer container, int number, string locationName)
{
container
.InternalLink(locationName)
.Row(row =>
{
row.ConstantItem(25).Text($"{number}.");
row.RelativeItem().Text(locationName);
2022-02-16 15:34:54 +01:00
row.ConstantItem(150).AlignRight().Text(text =>
{
2022-02-21 00:57:53 +01:00
text.BeginPageNumberOfSection(locationName);
2022-02-16 15:34:54 +01:00
text.Span(" - ");
2022-02-21 00:57:53 +01:00
text.EndPageNumberOfSection(locationName);
2022-02-16 15:34:54 +01:00
var lengthStyle = TextStyle.Default.Color(Colors.Grey.Medium);
text.Span(" (", lengthStyle);
2022-02-21 00:57:53 +01:00
text.TotalPagesWithinSection(locationName, lengthStyle, x => x == 1 ? "1 page long" : $"{x} pages long");
2022-02-16 15:34:54 +01:00
text.Span(")", lengthStyle);
});
});
}
}
}