From 4938e97e6d630f96c40e2bd46bde3e4884a605e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Zi=C4=85bek?= Date: Fri, 1 Oct 2021 14:09:25 +0200 Subject: [PATCH 1/2] Update readme.md --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index 1b6effb..457fe44 100644 --- a/readme.md +++ b/readme.md @@ -37,8 +37,11 @@ The library is available as a nuget package. You can install it as any other nug ## Documentation **[Release notes and roadmap](https://www.questpdf.com/documentation/releases.html)** - everything that is planned for future library iterations, description of new features and information about potential breaking changes. + **[Getting started tutorial](https://www.questpdf.com/documentation/getting-started.html)** - a short and easy to follow tutorial showing how to design an invoice document under 200 lines of code. + **[API Reference](https://www.questpdf.com/documentation/api-reference.html)** - a detailed description of behavior of all available components and how to use them with C# Fluent API. + **[Patterns and practices](https://www.questpdf.com/documentation/patterns-and-practices.html#document-metadata)** - everything that may help you designing great reports and reusable code that is easy to maintain. ## Example invoice From caa779e1e0d8b901d754a80f755e03260d2e13f7 Mon Sep 17 00:00:00 2001 From: jcl-aadlab Date: Tue, 5 Oct 2021 10:47:22 +0200 Subject: [PATCH 2/2] Added skip element for headers and footers --- .../Layouts/DifferentHeadersTemplate.cs | 85 +++++++++++++++++++ QuestPDF/Elements/SkipOnce.cs | 34 ++++++++ QuestPDF/Fluent/ElementExtensions.cs | 7 +- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 QuestPDF.ReportSample/Layouts/DifferentHeadersTemplate.cs create mode 100644 QuestPDF/Elements/SkipOnce.cs diff --git a/QuestPDF.ReportSample/Layouts/DifferentHeadersTemplate.cs b/QuestPDF.ReportSample/Layouts/DifferentHeadersTemplate.cs new file mode 100644 index 0000000..2b3898f --- /dev/null +++ b/QuestPDF.ReportSample/Layouts/DifferentHeadersTemplate.cs @@ -0,0 +1,85 @@ +using QuestPDF.Drawing; +using QuestPDF.Fluent; +using QuestPDF.Helpers; +using QuestPDF.Infrastructure; + +namespace QuestPDF.ReportSample.Layouts +{ + public class DifferentHeadersTemplate : IDocument + { + public DocumentMetadata GetMetadata() => DocumentMetadata.Default; + + public void Compose(IDocumentContainer container) + { + container + .Page(page => + { + page.Margin(40); + + page.Size(PageSizes.A4); + + page.Header().Element(ComposeHeader); + page.Content().Element(ComposeContent); + page.Footer().Element(ComposeFooter); + }); + } + + private void ComposeHeader(IContainer container) + { + container.Background(Colors.Grey.Lighten3).Border(1).Stack(stack => + { + stack.Item().ShowOnce().Padding(5).AlignMiddle().Row(row => + { + row.RelativeColumn(2).AlignMiddle().Text("PRIMARY HEADER", TextStyle.Default.Color(Colors.Grey.Darken3).Size(30).Bold()); + row.RelativeColumn(1).AlignRight().Box().AlignMiddle().Background(Colors.Blue.Darken2).Padding(30); + }); + stack.Item().SkipOnce().Padding(5).Row(row => + { + row.RelativeColumn(2).Text("SECONDARY HEADER", TextStyle.Default.Color(Colors.Grey.Darken3).Size(30).Bold()); + row.RelativeColumn(1).AlignRight().Box().Background(Colors.Blue.Lighten4).Padding(15); + }); + }); + } + + private void ComposeContent(IContainer container) + { + container.Stack(stack => + { + stack.Item().PaddingVertical(80).Text("First"); + stack.Item().PageBreak(); + stack.Item().PaddingVertical(80).Text("Second"); + stack.Item().PageBreak(); + stack.Item().PaddingVertical(80).Text("Third"); + stack.Item().PageBreak(); + }); + } + + private void ComposeFooter(IContainer container) + { + container.Background(Colors.Grey.Lighten3).Stack(stack => + { + stack.Item().ShowOnce().Background(Colors.Grey.Lighten3).Row(row => + { + row.RelativeColumn().Text(x => + { + x.CurrentPageNumber(); + x.Span(" / "); + x.TotalPages(); + }); + row.RelativeColumn().AlignRight().Text("Footer for header"); + }); + + stack.Item().SkipOnce().Background(Colors.Grey.Lighten3).Row(row => + { + row.RelativeColumn().Text(x => + { + x.CurrentPageNumber(); + x.Span(" / "); + x.TotalPages(); + }); + row.RelativeColumn().AlignRight().Text("Footer for every page except header"); + }); + }); + } + } +} \ No newline at end of file diff --git a/QuestPDF/Elements/SkipOnce.cs b/QuestPDF/Elements/SkipOnce.cs new file mode 100644 index 0000000..cf5ee5a --- /dev/null +++ b/QuestPDF/Elements/SkipOnce.cs @@ -0,0 +1,34 @@ +using QuestPDF.Drawing.SpacePlan; +using QuestPDF.Infrastructure; + +namespace QuestPDF.Elements +{ + internal class SkipOnce : ContainerElement, IStateResettable + { + private bool firstPageWasSkiped; + + public void ResetState() + { + firstPageWasSkiped = false; + } + + internal override ISpacePlan Measure(Size availableSpace) + { + if (Child == null || !firstPageWasSkiped) + return new FullRender(Size.Zero); + + return Child.Measure(availableSpace); + } + + internal override void Draw(Size availableSpace) + { + if (Child == null) + return; + + if (firstPageWasSkiped) + Child.Draw(availableSpace); + + firstPageWasSkiped = true; + } + } +} \ No newline at end of file diff --git a/QuestPDF/Fluent/ElementExtensions.cs b/QuestPDF/Fluent/ElementExtensions.cs index f41d050..895cf6e 100644 --- a/QuestPDF/Fluent/ElementExtensions.cs +++ b/QuestPDF/Fluent/ElementExtensions.cs @@ -70,7 +70,12 @@ namespace QuestPDF.Fluent { return element.Element(new ShowOnce()); } - + + public static IContainer SkipOnce(this IContainer element) + { + return element.Element(new SkipOnce()); + } + public static IContainer ShowEntire(this IContainer element) { return element.Element(new ShowEntire());