diff --git a/QuestPDF.Examples/BarCode.cs b/QuestPDF.Examples/BarCode.cs index f90aca1..fd4853b 100644 --- a/QuestPDF.Examples/BarCode.cs +++ b/QuestPDF.Examples/BarCode.cs @@ -18,7 +18,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(400, 100) - .FileName() .ShowResults() .Render(container => { diff --git a/QuestPDF.Examples/BarcodeExamples.cs b/QuestPDF.Examples/BarcodeExamples.cs index 5711c37..b9b3f9f 100644 --- a/QuestPDF.Examples/BarcodeExamples.cs +++ b/QuestPDF.Examples/BarcodeExamples.cs @@ -15,7 +15,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) - .FileName() .Render(container => { container diff --git a/QuestPDF.Examples/DefaultTextStyleExample.cs b/QuestPDF.Examples/DefaultTextStyleExample.cs new file mode 100644 index 0000000..c88f59c --- /dev/null +++ b/QuestPDF.Examples/DefaultTextStyleExample.cs @@ -0,0 +1,48 @@ +using NUnit.Framework; +using QuestPDF.Examples.Engine; +using QuestPDF.Fluent; +using QuestPDF.Helpers; +using QuestPDF.Infrastructure; + +namespace QuestPDF.Examples +{ + public class DefaultTextStyleExample + { + [Test] + public void DefaultTextStyle() + { + RenderingTest + .Create() + .ProduceImages() + .ShowResults() + .RenderDocument(container => + { + container.Page(page => + { + // all text in this set of pages has size 20 + page.DefaultTextStyle(TextStyle.Default.Size(20)); + + page.Margin(20); + page.Size(PageSizes.A4); + page.Background(Colors.White); + + page.Content().Stack(stack => + { + stack.Item().Text(Placeholders.Sentence()); + + stack.Item().Text(text => + { + // text in this block is additionally semibold + text.DefaultTextStyle(TextStyle.Default.SemiBold()); + + text.Line(Placeholders.Sentence()); + + // this text has size 20 but also semibold and red + text.Span(Placeholders.Sentence(), TextStyle.Default.Color(Colors.Red.Medium)); + }); + }); + }); + }); + } + } +} \ No newline at end of file diff --git a/QuestPDF.Examples/ElementExamples.cs b/QuestPDF.Examples/ElementExamples.cs index da81826..d1fb3a2 100644 --- a/QuestPDF.Examples/ElementExamples.cs +++ b/QuestPDF.Examples/ElementExamples.cs @@ -17,7 +17,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 150) - .FileName() .Render(container => { container @@ -33,7 +32,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) - .FileName() .Render(container => { container @@ -63,7 +61,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(740, 200) - .FileName() .Render(container => { container @@ -104,7 +101,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(740, 200) - .FileName() .Render(container => { container @@ -126,7 +122,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(500, 360) - .FileName() .Render(container => { container @@ -149,7 +144,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(210, 210) - .FileName() .Render(container => { container @@ -172,7 +166,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 200) - .FileName() .Render(container => { var text = ""; @@ -195,7 +188,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(400, 230) - .FileName() .Render(container => { var textStyle = TextStyle.Default.Size(14); @@ -230,7 +222,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 200) - .FileName() .Render(container => { container @@ -260,7 +251,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(400, 250) - .FileName() .Render(container => { container @@ -336,7 +326,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) - .FileName() .Render(container => { container @@ -381,7 +370,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(450, 150) - .FileName() .Render(container => { container @@ -414,7 +402,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(500, 175) - .FileName() .Render(container => { container @@ -441,7 +428,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) - .FileName() .Render(container => { container @@ -481,7 +467,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 150) - .FileName() .Render(container => { container @@ -502,7 +487,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 175) - .FileName() .Render(container => { container @@ -554,7 +538,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 200) - .FileName() .Render(container => { container @@ -582,7 +565,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(650, 450) - .FileName() .Render(container => { container @@ -621,7 +603,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) - .FileName() .Render(container => { container @@ -648,7 +629,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) - .FileName() .Render(container => { container @@ -680,7 +660,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(350, 350) - .FileName() .Render(container => { container @@ -722,7 +701,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 200) - .FileName() .Render(container => { container @@ -748,7 +726,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(400, 350) - .FileName() .Render(container => { container @@ -785,7 +762,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(500, 225) - .FileName() .Render(container => { container @@ -839,7 +815,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(600, 310) - .FileName() .Render(container => { container diff --git a/QuestPDF.Examples/Engine/RenderingTest.cs b/QuestPDF.Examples/Engine/RenderingTest.cs index e8aacf2..6279a99 100644 --- a/QuestPDF.Examples/Engine/RenderingTest.cs +++ b/QuestPDF.Examples/Engine/RenderingTest.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using QuestPDF.Elements; using QuestPDF.Fluent; +using QuestPDF.Helpers; using QuestPDF.Infrastructure; namespace QuestPDF.Examples.Engine @@ -25,12 +26,12 @@ namespace QuestPDF.Examples.Engine } - public static RenderingTest Create() + public static RenderingTest Create([CallerMemberName] string fileName = "test") { - return new RenderingTest(); + return new RenderingTest().FileName(fileName); } - public RenderingTest FileName([CallerMemberName] string fileName = "test") + public RenderingTest FileName(string fileName) { FileNamePrefix = fileName; return this; @@ -67,12 +68,26 @@ namespace QuestPDF.Examples.Engine public void Render(Action content) { - var container = new Container(); - content(container); + RenderDocument(container => + { + container.Page(page => + { + page.Size(new PageSize(Size.Width, Size.Height)); + page.Content().Container().Background(Colors.White).Element(content); + }); + }); + } + public void RenderDocument(Action content) + { var maxPages = ResultType == RenderingTestResult.Pdf ? 1000 : 10; - var document = new SimpleDocument(container, Size, maxPages); + var document = new SimpleDocument(content, maxPages); + Render(document); + } + + private void Render(IDocument document) + { if (ResultType == RenderingTestResult.Images) { Func fileNameSchema = i => $"{FileNamePrefix}-${i}.png"; diff --git a/QuestPDF.Examples/Engine/SimpleDocument.cs b/QuestPDF.Examples/Engine/SimpleDocument.cs index 9e2feb7..25d3887 100644 --- a/QuestPDF.Examples/Engine/SimpleDocument.cs +++ b/QuestPDF.Examples/Engine/SimpleDocument.cs @@ -1,4 +1,5 @@ -using QuestPDF.Drawing; +using System; +using QuestPDF.Drawing; using QuestPDF.Elements; using QuestPDF.Fluent; using QuestPDF.Helpers; @@ -10,14 +11,12 @@ namespace QuestPDF.Examples.Engine { public const int ImageScalingFactor = 2; - private IContainer Container { get; } - private Size Size { get; } + private Action Content { get; } private int MaxPages { get; } - public SimpleDocument(IContainer container, Size size, int maxPages) + public SimpleDocument(Action content, int maxPages) { - Container = container; - Size = size; + Content = content; MaxPages = maxPages; } @@ -32,11 +31,7 @@ namespace QuestPDF.Examples.Engine public void Compose(IDocumentContainer container) { - container.Page(page => - { - page.Size(new PageSize(Size.Width, Size.Height)); - page.Content().Container().Background(Colors.White).Element(Container as Container); - }); + Content(container); } } } \ No newline at end of file diff --git a/QuestPDF.Examples/EnsureSpaceExample.cs b/QuestPDF.Examples/EnsureSpaceExample.cs new file mode 100644 index 0000000..0808774 --- /dev/null +++ b/QuestPDF.Examples/EnsureSpaceExample.cs @@ -0,0 +1,53 @@ +using NUnit.Framework; +using QuestPDF.Examples.Engine; +using QuestPDF.Fluent; +using QuestPDF.Helpers; +using QuestPDF.Infrastructure; + +namespace QuestPDF.Examples +{ + public class EnsureSpaceExample + { + [Test] + public void EnsureSpaceWith() + { + RenderingTest + .Create() + .ProduceImages() + .ShowResults() + .RenderDocument(container => + { + container.Page(page => + { + page.Margin(20); + page.Size(PageSizes.A7.Landscape()); + page.Background(Colors.White); + + page.Header().Text("With ensure space", TextStyle.Default.SemiBold()); + + page.Content().Stack(stack => + { + stack + .Item() + .ExtendHorizontal() + .Height(75) + .Background(Colors.Grey.Lighten2); + + stack + .Item() + .EnsureSpace(100) + .Text(Placeholders.LoremIpsum()); + }); + + page.Footer().Text(text => + { + text.Span("Page "); + text.CurrentPageNumber(); + text.Span(" out of "); + text.TotalPages(); + }); + }); + }); + } + } +} \ No newline at end of file diff --git a/QuestPDF.Examples/FrameExample.cs b/QuestPDF.Examples/FrameExample.cs index f8d8ae0..614aa54 100644 --- a/QuestPDF.Examples/FrameExample.cs +++ b/QuestPDF.Examples/FrameExample.cs @@ -28,7 +28,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(550, 400) - .FileName() .ShowResults() .Render(container => { diff --git a/QuestPDF.Examples/InlinedExamples.cs b/QuestPDF.Examples/InlinedExamples.cs index 5b8f4a2..adf4e68 100644 --- a/QuestPDF.Examples/InlinedExamples.cs +++ b/QuestPDF.Examples/InlinedExamples.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Reflection.Metadata.Ecma335; using NUnit.Framework; using QuestPDF.Examples.Engine; using QuestPDF.Fluent; @@ -16,7 +17,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(800, 650) - .FileName() .ProduceImages() .ShowResults() .Render(container => @@ -81,5 +81,42 @@ namespace QuestPDF.Examples }); }); } + + [Test] + public void Inline_AlignLeft_BaselineBottom() + { + RenderingTest + .Create() + .PageSize(400, 250) + .ProduceImages() + .ShowResults() + .Render(container => + { + container + .Padding(20) + .Border(1) + .Background(Colors.Grey.Lighten3) + .Inlined(inlined => + { + inlined.VerticalSpacing(50); + inlined.HorizontalSpacing(20); + inlined.AlignSpaceAround(); + inlined.BaselineTop(); + + foreach (var _ in Enumerable.Range(0, 20)) + inlined.Item().Element(RandomBlock); + }); + }); + + void RandomBlock(IContainer container) + { + container + .Width(Placeholders.Random.Next(1, 5) * 20) + .Height(Placeholders.Random.Next(1, 5) * 20) + .Border(1) + .BorderColor(Colors.Grey.Darken2) + .Background(Placeholders.BackgroundColor()); + } + } } } \ No newline at end of file diff --git a/QuestPDF.Examples/LoremPicsumExample.cs b/QuestPDF.Examples/LoremPicsumExample.cs index 3919bec..c20094a 100644 --- a/QuestPDF.Examples/LoremPicsumExample.cs +++ b/QuestPDF.Examples/LoremPicsumExample.cs @@ -36,7 +36,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(350, 280) - .FileName() .Render(container => { container diff --git a/QuestPDF.Examples/Padding.cs b/QuestPDF.Examples/Padding.cs index 6d7bfca..e20b71b 100644 --- a/QuestPDF.Examples/Padding.cs +++ b/QuestPDF.Examples/Padding.cs @@ -13,7 +13,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) - .FileName() .ShowResults() .Render(container => { @@ -37,7 +36,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 150) - .FileName() .Render(container => { container @@ -62,7 +60,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 150) - .FileName() .Render(container => { container @@ -113,7 +110,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 150) - .FileName() .Render(container => { container diff --git a/QuestPDF.Examples/ShowOnceExample.cs b/QuestPDF.Examples/ShowOnceExample.cs new file mode 100644 index 0000000..72e4727 --- /dev/null +++ b/QuestPDF.Examples/ShowOnceExample.cs @@ -0,0 +1,54 @@ +using NUnit.Framework; +using QuestPDF.Examples.Engine; +using QuestPDF.Fluent; +using QuestPDF.Helpers; +using QuestPDF.Infrastructure; + +namespace QuestPDF.Examples +{ + public class ShowOnceExample + { + [Test] + public void ShowOnce() + { + RenderingTest + .Create() + .ProduceImages() + .ShowResults() + .RenderDocument(container => + { + container.Page(page => + { + page.Margin(20); + page.Size(PageSizes.A7.Landscape()); + page.Background(Colors.White); + + page.Header().Text("With show once", TextStyle.Default.SemiBold()); + + page.Content().PaddingVertical(5).Row(row => + { + row.RelativeColumn() + .Background(Colors.Grey.Lighten2) + .Border(1) + .Padding(5) + .ShowOnce() + .Text(Placeholders.Label()); + + row.RelativeColumn(2) + .Border(1) + .Padding(5) + .Text(Placeholders.Paragraph()); + }); + + page.Footer().Text(text => + { + text.Span("Page "); + text.CurrentPageNumber(); + text.Span(" out of "); + text.TotalPages(); + }); + }); + }); + } + } +} \ No newline at end of file diff --git a/QuestPDF.Examples/SkipOnceExample.cs b/QuestPDF.Examples/SkipOnceExample.cs new file mode 100644 index 0000000..8e73e9d --- /dev/null +++ b/QuestPDF.Examples/SkipOnceExample.cs @@ -0,0 +1,47 @@ +using NUnit.Framework; +using QuestPDF.Examples.Engine; +using QuestPDF.Fluent; +using QuestPDF.Helpers; +using QuestPDF.Infrastructure; + +namespace QuestPDF.Examples +{ + public class SkipOnceExample + { + [Test] + public void SkipOnce() + { + RenderingTest + .Create() + .ProduceImages() + .ShowResults() + .RenderDocument(container => + { + container.Page(page => + { + page.Margin(20); + page.Size(PageSizes.A7.Landscape()); + page.Background(Colors.White); + + page.Header().Stack(stack => + { + stack.Item().ShowOnce().Text("This header is visible on the first page."); + stack.Item().SkipOnce().Text("This header is visible on the second page and all following."); + }); + + page.Content() + .PaddingVertical(10) + .Text(Placeholders.Paragraphs(), TextStyle.Default.Color(Colors.Grey.Medium)); + + page.Footer().Text(text => + { + text.Span("Page "); + text.CurrentPageNumber(); + text.Span(" out of "); + text.TotalPages(); + }); + }); + }); + } + } +} \ No newline at end of file diff --git a/QuestPDF.Examples/TextBenchmark.cs b/QuestPDF.Examples/TextBenchmark.cs index 990a370..301df11 100644 --- a/QuestPDF.Examples/TextBenchmark.cs +++ b/QuestPDF.Examples/TextBenchmark.cs @@ -21,7 +21,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(PageSizes.A4) - .FileName() .ProducePdf() .ShowResults() .Render(x => ComposeBook(x, chapters)); @@ -43,8 +42,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(PageSizes.A4) - .FileName() - .ProducePdf() + .ProducePdf() .Render(x => ComposeBook(x, chapters)); } diff --git a/QuestPDF.Examples/TextExamples.cs b/QuestPDF.Examples/TextExamples.cs index b01400f..9d1b82e 100644 --- a/QuestPDF.Examples/TextExamples.cs +++ b/QuestPDF.Examples/TextExamples.cs @@ -17,7 +17,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(500, 300) - .FileName() + .ProduceImages() .ShowResults() .Render(container => @@ -42,7 +42,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(500, 300) - .FileName() .ProduceImages() .ShowResults() .Render(container => @@ -71,7 +70,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(500, 200) - .FileName() .ProduceImages() .ShowResults() .Render(container => @@ -103,7 +101,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(PageSizes.A4) - .FileName() .ProducePdf() .ShowResults() .Render(container => @@ -134,7 +131,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(PageSizes.A4) - .FileName() .ProducePdf() .ShowResults() .Render(container => @@ -164,7 +160,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(PageSizes.A4) - .FileName() .ProducePdf() .ShowResults() .Render(container => @@ -228,7 +223,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(PageSizes.A4) - .FileName() .ProducePdf() .ShowResults() .Render(container =>