diff --git a/QuestPDF.Examples/ElementExamples.cs b/QuestPDF.Examples/ElementExamples.cs index 0d88bde..47f26b0 100644 --- a/QuestPDF.Examples/ElementExamples.cs +++ b/QuestPDF.Examples/ElementExamples.cs @@ -295,7 +295,7 @@ namespace QuestPDF.Examples layers .Layer() .AlignBottom() - .PageNumber("Page {pdf:currentPage}", TextStyle.Default.Size(16).Color(Colors.Green.Medium)); + .Text(text => text.CurrentPageNumber(TextStyle.Default.Size(16).Color(Colors.Green.Medium))); }); }); } diff --git a/QuestPDF.Examples/TextBenchmark.cs b/QuestPDF.Examples/TextBenchmark.cs index 11c725e..07942c6 100644 --- a/QuestPDF.Examples/TextBenchmark.cs +++ b/QuestPDF.Examples/TextBenchmark.cs @@ -143,8 +143,8 @@ namespace QuestPDF.Examples .AlignBottom() .Stack(stack => { - stack.Item().Debug().Text("Quo Vadis", TextStyle.Default.Size(72).Bold().Color(Colors.Blue.Darken2)); - stack.Item().Debug().Text("Henryk Sienkiewicz", TextStyle.Default.Size(24).Color(Colors.Grey.Darken2)); + stack.Item().Text("Quo Vadis", TextStyle.Default.Size(72).Bold().Color(Colors.Blue.Darken2)); + stack.Item().Text("Henryk Sienkiewicz", TextStyle.Default.Size(24).Color(Colors.Grey.Darken2)); }); } diff --git a/QuestPDF.Examples/TextExamples.cs b/QuestPDF.Examples/TextExamples.cs index 74824ac..90bfdae 100644 --- a/QuestPDF.Examples/TextExamples.cs +++ b/QuestPDF.Examples/TextExamples.cs @@ -37,7 +37,7 @@ namespace QuestPDF.Examples text.Span(Placeholders.LoremIpsum(), TextStyle.Default.Size(12)); text.Span("Before element - "); - text.Element().PaddingBottom(-10).Background(Colors.Red.Lighten4).Width(50).Height(20); + text.Element().PaddingBottom(-10).Background(Colors.Red.Lighten4).Height(20).PaddingHorizontal(5).AlignMiddle().Text("Text inside text", TextStyle.Default.Size(8)); text.Span(" - end of element."); text.NewLine(); diff --git a/QuestPDF.Examples/optimization.md b/QuestPDF.Examples/optimization.md index 93c4fe1..33dc08e 100644 --- a/QuestPDF.Examples/optimization.md +++ b/QuestPDF.Examples/optimization.md @@ -4,7 +4,7 @@ Attempts: -```angular2html +``` Attempt 0: 18389,00 Attempt 1: 18627,00 Attempt 2: 19745,00 diff --git a/QuestPDF.ReportSample/DataSource.cs b/QuestPDF.ReportSample/DataSource.cs index cb4e7e1..1b278c2 100644 --- a/QuestPDF.ReportSample/DataSource.cs +++ b/QuestPDF.ReportSample/DataSource.cs @@ -18,8 +18,8 @@ namespace QuestPDF.ReportSample HeaderFields = HeaderFields(), LogoData = Helpers.GetImage("Logo.png"), - Sections = Enumerable.Range(0, 50).Select(x => GenerateSection()).ToList(), - Photos = Enumerable.Range(0, 30).Select(x => GetReportPhotos()).ToList() + Sections = Enumerable.Range(0, 40).Select(x => GenerateSection()).ToList(), + Photos = Enumerable.Range(0, 25).Select(x => GetReportPhotos()).ToList() }; List HeaderFields() diff --git a/QuestPDF.ReportSample/Layouts/SectionTemplate.cs b/QuestPDF.ReportSample/Layouts/SectionTemplate.cs index 147862e..f8da682 100644 --- a/QuestPDF.ReportSample/Layouts/SectionTemplate.cs +++ b/QuestPDF.ReportSample/Layouts/SectionTemplate.cs @@ -28,13 +28,13 @@ namespace QuestPDF.ReportSample.Layouts { foreach (var part in Model.Parts) { - stack.Item().Row(row => + stack.Item().EnsureSpace(25).Row(row => { row.ConstantColumn(150).LabelCell().Text(part.Label, Typography.Normal); var frame = row.RelativeColumn().ValueCell(); if (part is ReportSectionText text) - frame.Text(text.Text, Typography.Normal); + frame.ShowEntire().Text(text.Text, Typography.Normal); if (part is ReportSectionMap map) frame.Element(x => MapElement(x, map)); diff --git a/QuestPDF.ReportSample/Layouts/StandardReport.cs b/QuestPDF.ReportSample/Layouts/StandardReport.cs index 16022e1..c130b82 100644 --- a/QuestPDF.ReportSample/Layouts/StandardReport.cs +++ b/QuestPDF.ReportSample/Layouts/StandardReport.cs @@ -34,7 +34,15 @@ namespace QuestPDF.ReportSample.Layouts page.Header().Element(ComposeHeader); page.Content().Element(ComposeContent); - page.Footer().AlignCenter().PageNumber(); + + page.Footer().AlignCenter().Text(text => + { + text.DefaultTextStyle(Typography.Normal); + + text.CurrentPageNumber(); + text.Span(" / "); + text.TotalPages(); + }); }); } @@ -77,6 +85,8 @@ namespace QuestPDF.ReportSample.Layouts stack.Item().Component(new TableOfContentsTemplate(Model.Sections)); + stack.Item().PageBreak(); + foreach (var section in Model.Sections) stack.Item().Location(section.Title).Component(new SectionTemplate(section)); diff --git a/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs b/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs index ddb90df..087cfff 100644 --- a/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs +++ b/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs @@ -43,7 +43,7 @@ namespace QuestPDF.ReportSample.Layouts { row.ConstantColumn(25).Text($"{number}.", Typography.Normal); row.RelativeColumn().Text(locationName, Typography.Normal); - row.ConstantColumn(150).AlignRight().PageNumber($"Page {{pdf:{locationName}}}"); + row.ConstantColumn(150).AlignRight().Text(text => text.PageNumberOfLocation(locationName, Typography.Normal)); }); } } diff --git a/QuestPDF.ReportSample/Tests.cs b/QuestPDF.ReportSample/Tests.cs index 8624a51..08b9995 100644 --- a/QuestPDF.ReportSample/Tests.cs +++ b/QuestPDF.ReportSample/Tests.cs @@ -28,7 +28,7 @@ namespace QuestPDF.ReportSample // target document length should be around 100 pages // test size - const int testSize = 25; + const int testSize = 10; const decimal performanceTarget = 1; // documents per second // create report models diff --git a/QuestPDF/Elements/PageNumber.cs b/QuestPDF/Elements/PageNumber.cs deleted file mode 100644 index 2369a83..0000000 --- a/QuestPDF/Elements/PageNumber.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Text.RegularExpressions; -using QuestPDF.Drawing.SpacePlan; -using QuestPDF.Infrastructure; -using Size = QuestPDF.Infrastructure.Size; - -namespace QuestPDF.Elements -{ - internal class PageNumber : Element - { - public string TextFormat { get; set; } = ""; - //private Text TextElement { get; set; } = new Text(); - - // public TextStyle? TextStyle - // { - // get => TextElement?.Style; - // set => TextElement.Style = value; - // } - - internal override void HandleVisitor(Action visit) - { - //TextElement?.HandleVisitor(visit); - base.HandleVisitor(visit); - } - - internal override ISpacePlan Measure(Size availableSpace) - { - //TextElement.Value = GetText(); - //return TextElement.Measure(availableSpace); - return new FullRender(Size.Zero); - } - - internal override void Draw(Size availableSpace) - { - //TextElement.Value = GetText(); - //TextElement.Draw(availableSpace); - } - - private string GetText() - { - var result = TextFormat; - - // replace known locations - foreach (var location in PageContext.GetRegisteredLocations()) - result = result.Replace($"{{pdf:{location}}}", PageContext.GetLocationPage(location).ToString()); - - // placeholder unknown locations - result = Regex.Replace(result, @"{pdf:[ \w]+}", "123"); - - return result; - } - } -} \ No newline at end of file diff --git a/QuestPDF/Fluent/ElementExtensions.cs b/QuestPDF/Fluent/ElementExtensions.cs index 98053c0..36afa74 100644 --- a/QuestPDF/Fluent/ElementExtensions.cs +++ b/QuestPDF/Fluent/ElementExtensions.cs @@ -40,15 +40,6 @@ namespace QuestPDF.Fluent { return handler(parent.Container()).Container(); } - - public static void PageNumber(this IContainer element, string textFormat = "{pdf:currentPage} / {pdf:totalPages}", TextStyle? style = null) - { - element.Element(new PageNumber - { - TextFormat = textFormat, - //TextStyle = style ?? TextStyle.Default // TODO - }); - } public static IContainer AspectRatio(this IContainer element, float ratio, AspectRatioOption option = AspectRatioOption.FitWidth) {