|
@@ -1,11 +1,9 @@
|
|
|
using System;
|
|
using System;
|
|
|
-using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using NUnit.Framework;
|
|
using NUnit.Framework;
|
|
|
-using QuestPDF.Drawing;
|
|
|
|
|
using QuestPDF.Examples.Engine;
|
|
using QuestPDF.Examples.Engine;
|
|
|
using QuestPDF.Fluent;
|
|
using QuestPDF.Fluent;
|
|
|
using QuestPDF.Helpers;
|
|
using QuestPDF.Helpers;
|
|
@@ -14,50 +12,31 @@ using QuestPDF.Infrastructure;
|
|
|
namespace QuestPDF.Examples
|
|
namespace QuestPDF.Examples
|
|
|
{
|
|
{
|
|
|
public class TextBenchmark
|
|
public class TextBenchmark
|
|
|
- {
|
|
|
|
|
|
|
+ {
|
|
|
[Test]
|
|
[Test]
|
|
|
- public void Benchmark()
|
|
|
|
|
|
|
+ public void Generate()
|
|
|
{
|
|
{
|
|
|
- var subtitleStyle = TextStyle.Default.Size(24).SemiBold().Color(Colors.Blue.Medium);
|
|
|
|
|
- var normalStyle = TextStyle.Default.Size(14);
|
|
|
|
|
|
|
+ var chapters = GetBookChapters().ToList();
|
|
|
|
|
|
|
|
- var chapters = GetChapters().ToList();
|
|
|
|
|
|
|
+ RenderingTest
|
|
|
|
|
+ .Create()
|
|
|
|
|
+ .PageSize(PageSizes.A4)
|
|
|
|
|
+ .FileName()
|
|
|
|
|
+ .ProducePdf()
|
|
|
|
|
+ .ShowResults()
|
|
|
|
|
+ .Render(x => ComposeBook(x, chapters));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Test]
|
|
|
|
|
+ public void Benchmark()
|
|
|
|
|
+ {
|
|
|
|
|
+ var chapters = GetBookChapters().ToList();
|
|
|
|
|
|
|
|
var results = PerformTest(16).ToList();
|
|
var results = PerformTest(16).ToList();
|
|
|
|
|
|
|
|
Console.WriteLine($"Min: {results.Min():F}");
|
|
Console.WriteLine($"Min: {results.Min():F}");
|
|
|
Console.WriteLine($"Max: {results.Max():F}");
|
|
Console.WriteLine($"Max: {results.Max():F}");
|
|
|
Console.WriteLine($"Avg: {results.Average():F}");
|
|
Console.WriteLine($"Avg: {results.Average():F}");
|
|
|
-
|
|
|
|
|
- IEnumerable<(string title, string content)> GetChapters()
|
|
|
|
|
- {
|
|
|
|
|
- var book = File.ReadAllLines("quo-vadis.txt");
|
|
|
|
|
-
|
|
|
|
|
- var chapterPointers = book
|
|
|
|
|
- .Select((line, index) => new
|
|
|
|
|
- {
|
|
|
|
|
- LineNumber = index,
|
|
|
|
|
- Text = line
|
|
|
|
|
- })
|
|
|
|
|
- .Where(x => x.Text.Length < 50 && x.Text.Contains("Rozdział") || x.Text.Contains("-----"))
|
|
|
|
|
- .Select(x => x.LineNumber)
|
|
|
|
|
- .ToList();
|
|
|
|
|
-
|
|
|
|
|
- foreach (var index in Enumerable.Range(0, chapterPointers.Count - 1))
|
|
|
|
|
- {
|
|
|
|
|
- var chapter = chapterPointers[index];
|
|
|
|
|
-
|
|
|
|
|
- var title = book[chapter];
|
|
|
|
|
-
|
|
|
|
|
- var lineFrom = chapterPointers[index];
|
|
|
|
|
- var lineTo = chapterPointers[index + 1] - 1;
|
|
|
|
|
-
|
|
|
|
|
- var lines = book.Skip(lineFrom + 1).Take(lineTo - lineFrom);
|
|
|
|
|
- var content = string.Join(Environment.NewLine, lines);
|
|
|
|
|
-
|
|
|
|
|
- yield return (title, content);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
void GenerateDocument()
|
|
void GenerateDocument()
|
|
|
{
|
|
{
|
|
@@ -66,7 +45,7 @@ namespace QuestPDF.Examples
|
|
|
.PageSize(PageSizes.A4)
|
|
.PageSize(PageSizes.A4)
|
|
|
.FileName()
|
|
.FileName()
|
|
|
.ProducePdf()
|
|
.ProducePdf()
|
|
|
- .Render(ComposePage);
|
|
|
|
|
|
|
+ .Render(x => ComposeBook(x, chapters));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
IEnumerable<float> PerformTest(int attempts)
|
|
IEnumerable<float> PerformTest(int attempts)
|
|
@@ -83,6 +62,54 @@ namespace QuestPDF.Examples
|
|
|
yield return timer.ElapsedMilliseconds;
|
|
yield return timer.ElapsedMilliseconds;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ class BookChapter
|
|
|
|
|
+ {
|
|
|
|
|
+ public string Title { get; set; }
|
|
|
|
|
+ public string Content { get; set; }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static IEnumerable<BookChapter> GetBookChapters()
|
|
|
|
|
+ {
|
|
|
|
|
+ var book = File.ReadAllLines("quo-vadis.txt");
|
|
|
|
|
+
|
|
|
|
|
+ var chapterPointers = book
|
|
|
|
|
+ .Select((line, index) => new
|
|
|
|
|
+ {
|
|
|
|
|
+ LineNumber = index,
|
|
|
|
|
+ Text = line
|
|
|
|
|
+ })
|
|
|
|
|
+ .Where(x => x.Text.Length < 50 && x.Text.Contains("Rozdział") || x.Text.Contains("-----"))
|
|
|
|
|
+ .Select(x => x.LineNumber)
|
|
|
|
|
+ .ToList();
|
|
|
|
|
+
|
|
|
|
|
+ foreach (var index in Enumerable.Range(0, chapterPointers.Count - 1))
|
|
|
|
|
+ {
|
|
|
|
|
+ var chapter = chapterPointers[index];
|
|
|
|
|
+
|
|
|
|
|
+ var title = book[chapter];
|
|
|
|
|
+
|
|
|
|
|
+ var lineFrom = chapterPointers[index];
|
|
|
|
|
+ var lineTo = chapterPointers[index + 1] - 1;
|
|
|
|
|
+
|
|
|
|
|
+ var lines = book.Skip(lineFrom + 1).Take(lineTo - lineFrom);
|
|
|
|
|
+ var content = string.Join(Environment.NewLine, lines);
|
|
|
|
|
+
|
|
|
|
|
+ yield return new BookChapter
|
|
|
|
|
+ {
|
|
|
|
|
+ Title = title,
|
|
|
|
|
+ Content = content
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void ComposeBook(IContainer container, ICollection<BookChapter> chapters)
|
|
|
|
|
+ {
|
|
|
|
|
+ var subtitleStyle = TextStyle.Default.Size(24).SemiBold().Color(Colors.Blue.Medium);
|
|
|
|
|
+ var normalStyle = TextStyle.Default.Size(14);
|
|
|
|
|
+
|
|
|
|
|
+ ComposePage(container);
|
|
|
|
|
|
|
|
void ComposePage(IContainer container)
|
|
void ComposePage(IContainer container)
|
|
|
{
|
|
{
|
|
@@ -128,10 +155,10 @@ namespace QuestPDF.Examples
|
|
|
|
|
|
|
|
foreach (var chapter in chapters)
|
|
foreach (var chapter in chapters)
|
|
|
{
|
|
{
|
|
|
- stack.Item().InternalLink(chapter.title).Row(row =>
|
|
|
|
|
|
|
+ stack.Item().InternalLink(chapter.Title).Row(row =>
|
|
|
{
|
|
{
|
|
|
- row.RelativeColumn().Text(chapter.title);
|
|
|
|
|
- row.ConstantColumn(100).AlignRight().Text(text => text.PageNumberOfLocation(chapter.title, normalStyle));
|
|
|
|
|
|
|
+ row.RelativeColumn().Text(chapter.Title);
|
|
|
|
|
+ row.ConstantColumn(100).AlignRight().Text(text => text.PageNumberOfLocation(chapter.Title, normalStyle));
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -141,7 +168,7 @@ namespace QuestPDF.Examples
|
|
|
{
|
|
{
|
|
|
foreach (var chapter in chapters)
|
|
foreach (var chapter in chapters)
|
|
|
{
|
|
{
|
|
|
- stack.Item().Element(container => Chapter(container, chapter.title, chapter.content));
|
|
|
|
|
|
|
+ stack.Item().Element(container => Chapter(container, chapter.Title, chapter.Content));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|