Files

89 lines
2.8 KiB
C#
Raw Permalink Normal View History

2021-01-16 01:31:39 +01:00
using QuestPDF.Drawing;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace QuestPDF.ReportSample.Layouts
{
public class StandardReport : IDocument
{
private ReportModel Model { get; }
public StandardReport(ReportModel model)
{
Model = model;
}
public DocumentMetadata GetMetadata()
{
return new DocumentMetadata()
{
Title = Model.Title,
Size = PageSizes.A4
};
}
public void Compose(IContainer container)
{
container
.PaddingVertical(40)
.PaddingHorizontal(50)
.Page(page =>
{
page.Header().Element(ComposeHeader);
page.Content().Element(ComposeContent);
2021-01-16 01:31:39 +01:00
page.Footer().AlignCenter().PageNumber("Page {number}");
});
}
private void ComposeHeader(IContainer container)
{
2021-04-20 12:55:07 +02:00
container.Stack(stack =>
2021-01-16 01:31:39 +01:00
{
2021-05-01 22:46:37 +02:00
stack.Item().Row(row =>
2021-01-16 01:31:39 +01:00
{
2021-04-20 12:55:07 +02:00
row.Spacing(50);
2021-01-16 01:31:39 +01:00
2021-04-20 12:55:07 +02:00
row.RelativeColumn().PaddingTop(-10).Text(Model.Title, Typography.Title);
row.ConstantColumn(150).ExternalLink("https://www.questpdf.com").Image(Model.LogoData);
2021-01-16 01:31:39 +01:00
});
2021-04-20 12:55:07 +02:00
2021-05-01 22:46:37 +02:00
stack.Item().ShowOnce().PaddingVertical(15).Border(1f).BorderColor(Colors.Grey.Lighten1).ExtendHorizontal();
2021-01-16 01:31:39 +01:00
2021-05-01 22:46:37 +02:00
stack.Item().ShowOnce().Grid(grid =>
2021-04-20 12:55:07 +02:00
{
grid.Columns(2);
grid.Spacing(5);
foreach (var field in Model.HeaderFields)
{
grid.Item().Stack(row =>
2021-04-20 12:55:07 +02:00
{
2021-05-01 22:46:37 +02:00
row.Item().AlignLeft().Text(field.Label, Typography.Normal.SemiBold());
row.Item().Text(field.Value, Typography.Normal);
2021-04-20 12:55:07 +02:00
});
}
});
2021-01-16 01:31:39 +01:00
});
}
void ComposeContent(IContainer container)
{
container.PaddingVertical(20).Stack(stack =>
2021-01-16 01:31:39 +01:00
{
stack.Spacing(20);
2021-05-01 22:46:37 +02:00
stack.Item().Component(new TableOfContentsTemplate(Model.Sections));
2021-01-16 01:31:39 +01:00
foreach (var section in Model.Sections)
2021-05-01 22:46:37 +02:00
stack.Item().Location(section.Title).Component(new SectionTemplate(section));
2021-01-16 01:31:39 +01:00
2021-05-01 22:46:37 +02:00
stack.Item().PageBreak();
stack.Item().Location("Photos");
2021-01-16 01:31:39 +01:00
foreach (var photo in Model.Photos)
2021-05-01 22:46:37 +02:00
stack.Item().Component(new PhotoTemplate(photo));
2021-01-16 01:31:39 +01:00
});
}
}
}