2021-04-17 21:52:33 +02:00
|
|
|
using System.Collections.Generic;
|
2022-02-16 15:34:54 +01:00
|
|
|
using System.Drawing;
|
2021-02-08 14:36:12 +01:00
|
|
|
using QuestPDF.Fluent;
|
2022-02-16 15:34:54 +01:00
|
|
|
using QuestPDF.Helpers;
|
2021-02-08 14:36:12 +01:00
|
|
|
using QuestPDF.Infrastructure;
|
2022-05-24 23:50:53 +02:00
|
|
|
using SkiaSharp;
|
2021-02-08 14:36:12 +01:00
|
|
|
|
|
|
|
|
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
|
2022-01-16 17:08:57 +01:00
|
|
|
.Before()
|
2021-02-08 14:36:12 +01:00
|
|
|
.PaddingBottom(5)
|
2022-03-08 17:27:30 +01:00
|
|
|
.Text("Table of contents")
|
|
|
|
|
.Style(Typography.Headline);
|
2021-02-08 14:36:12 +01:00
|
|
|
|
2022-01-09 00:11:34 +01:00
|
|
|
decoration.Content().Column(column =>
|
2021-02-08 14:36:12 +01:00
|
|
|
{
|
2022-01-09 00:11:34 +01:00
|
|
|
column.Spacing(5);
|
2021-02-08 14:36:12 +01:00
|
|
|
|
|
|
|
|
for (var i = 0; i < Sections.Count; i++)
|
2022-01-09 00:11:34 +01:00
|
|
|
column.Item().Element(c => DrawLink(c, i+1, Sections[i].Title));
|
2021-02-08 14:36:12 +01:00
|
|
|
|
2022-01-09 00:11:34 +01:00
|
|
|
column.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
|
2022-04-29 11:36:28 +02:00
|
|
|
.SectionLink(locationName)
|
2021-02-08 14:36:12 +01:00
|
|
|
.Row(row =>
|
|
|
|
|
{
|
2022-05-24 23:50:53 +02:00
|
|
|
row.ConstantItem(20).Text($"{number}.");
|
|
|
|
|
row.AutoItem().Text(locationName);
|
|
|
|
|
|
|
|
|
|
row.RelativeItem().PaddingHorizontal(2).AlignBottom().TranslateY(-3).Height(1).Canvas((canvas, space) =>
|
|
|
|
|
{
|
|
|
|
|
// best to statically cache
|
|
|
|
|
using var paint = new SKPaint
|
|
|
|
|
{
|
|
|
|
|
StrokeWidth = space.Height,
|
|
|
|
|
PathEffect = SKPathEffect.CreateDash(new float[] { 1, 3 }, 0)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
canvas.DrawLine(0, 0, space.Width, 0, paint);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
row.AutoItem().Text(text =>
|
2022-02-16 15:34:54 +01:00
|
|
|
{
|
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
|
|
|
|
2022-04-29 11:36:28 +02:00
|
|
|
var lengthStyle = TextStyle.Default.FontColor(Colors.Grey.Medium);
|
2022-02-16 15:34:54 +01:00
|
|
|
|
2022-10-19 21:45:16 +02:00
|
|
|
text.TotalPagesWithinSection(locationName).Style(lengthStyle).Format(x =>
|
|
|
|
|
{
|
|
|
|
|
var formatted = x == 1 ? "1 page long" : $"{x} pages long";
|
2022-11-01 21:51:45 +01:00
|
|
|
return $" ({formatted})";
|
2022-10-19 21:45:16 +02:00
|
|
|
});
|
2022-02-16 15:34:54 +01:00
|
|
|
});
|
2021-02-08 14:36:12 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-29 11:36:28 +02:00
|
|
|
}
|