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()
|
|
|
|
|
{
|
2021-07-26 11:35:52 +02:00
|
|
|
Title = Model.Title
|
2021-01-16 01:31:39 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 11:35:52 +02:00
|
|
|
public void Compose(IDocumentContainer container)
|
2021-01-16 01:31:39 +01:00
|
|
|
{
|
|
|
|
|
container
|
|
|
|
|
.Page(page =>
|
|
|
|
|
{
|
2021-10-23 02:59:29 +02:00
|
|
|
page.DefaultTextStyle(Typography.Normal);
|
|
|
|
|
|
2021-07-26 11:35:52 +02:00
|
|
|
page.MarginVertical(40);
|
|
|
|
|
page.MarginHorizontal(50);
|
|
|
|
|
|
|
|
|
|
page.Size(PageSizes.A4);
|
|
|
|
|
|
2021-05-02 21:11:08 +02:00
|
|
|
page.Header().Element(ComposeHeader);
|
|
|
|
|
page.Content().Element(ComposeContent);
|
2021-08-27 11:40:33 +02:00
|
|
|
|
|
|
|
|
page.Footer().AlignCenter().Text(text =>
|
|
|
|
|
{
|
|
|
|
|
text.CurrentPageNumber();
|
|
|
|
|
text.Span(" / ");
|
|
|
|
|
text.TotalPages();
|
|
|
|
|
});
|
2021-01-16 01:31:39 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2021-11-07 16:19:54 +01:00
|
|
|
row.ConstantColumn(90).ExternalLink("https://www.questpdf.com").MaxHeight(30).Component<ImagePlaceholder>();
|
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)
|
|
|
|
|
{
|
2021-08-25 03:40:16 +02:00
|
|
|
grid.Item().Text(text =>
|
|
|
|
|
{
|
2021-10-07 23:23:07 +02:00
|
|
|
text.Span($"{field.Label}: ", TextStyle.Default.SemiBold());
|
|
|
|
|
text.Span(field.Value);
|
2021-04-20 12:55:07 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-01-16 01:31:39 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComposeContent(IContainer container)
|
|
|
|
|
{
|
2021-03-28 17:49:19 +02:00
|
|
|
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-02-08 14:36:12 +01:00
|
|
|
|
2021-08-27 11:40:33 +02:00
|
|
|
stack.Item().PageBreak();
|
|
|
|
|
|
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-02-08 14:36:12 +01:00
|
|
|
|
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
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|