Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f927ec402 | |||
| 9dc3e2b533 |
@@ -1,32 +0,0 @@
|
|||||||
using System.IO;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Drawing;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
public class BarCode
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void Example()
|
|
||||||
{
|
|
||||||
FontManager.RegisterFontType("LibreBarcode39", File.OpenRead("LibreBarcode39-Regular.ttf"));
|
|
||||||
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(400, 100)
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background(Colors.White)
|
|
||||||
.AlignCenter()
|
|
||||||
.AlignMiddle()
|
|
||||||
.Text("*QuestPDF*", TextStyle.Default.FontType("LibreBarcode39").Size(64));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class BarcodeExamples
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void Barcode()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 300)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background("#FFF")
|
|
||||||
.Padding(25)
|
|
||||||
.Stack(stack =>
|
|
||||||
{
|
|
||||||
stack.Item().Border(1).Background(Colors.Grey.Lighten3).Padding(5).Text("Barcode Example");
|
|
||||||
stack.Item().Border(1).Padding(5).AlignCenter().Text("*123456789*", TextStyle.Default.FontType("CarolinaBar-Demo-25E2").Size(20));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
using Microcharts;
|
|
||||||
using SkiaSharp;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
public class ChartExample
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void MicrochartChart()
|
|
||||||
{
|
|
||||||
var entries = new[]
|
|
||||||
{
|
|
||||||
new ChartEntry(212)
|
|
||||||
{
|
|
||||||
Label = "UWP",
|
|
||||||
ValueLabel = "112",
|
|
||||||
Color = SKColor.Parse("#2c3e50")
|
|
||||||
},
|
|
||||||
new ChartEntry(248)
|
|
||||||
{
|
|
||||||
Label = "Android",
|
|
||||||
ValueLabel = "648",
|
|
||||||
Color = SKColor.Parse("#77d065")
|
|
||||||
},
|
|
||||||
new ChartEntry(128)
|
|
||||||
{
|
|
||||||
Label = "iOS",
|
|
||||||
ValueLabel = "428",
|
|
||||||
Color = SKColor.Parse("#b455b6")
|
|
||||||
},
|
|
||||||
new ChartEntry(514)
|
|
||||||
{
|
|
||||||
Label = "Forms",
|
|
||||||
ValueLabel = "214",
|
|
||||||
Color = SKColor.Parse("#3498db")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 300)
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container.Extend().Canvas((canvas, size) =>
|
|
||||||
{
|
|
||||||
var bar = new BarChart
|
|
||||||
{
|
|
||||||
Entries = entries,
|
|
||||||
IsAnimated = false,
|
|
||||||
};
|
|
||||||
bar.Draw(canvas, (int)size.Width, (int)size.Height);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
public class ComplexLayoutBenchmark
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void ComplexLayout()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(PageSizes.A4)
|
|
||||||
.ProducePdf()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(x => x.Image(new byte[] { 1, 2, 3 }));
|
|
||||||
//.Render(x => GenerateStructure(x, 16));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GenerateStructure(IContainer container, int level)
|
|
||||||
{
|
|
||||||
if (level <= 0)
|
|
||||||
{
|
|
||||||
container.Background(Placeholders.BackgroundColor()).Height(10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
level--;
|
|
||||||
|
|
||||||
if (level % 3 == 0)
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Border(level / 10f)
|
|
||||||
.BorderColor(Colors.Black)
|
|
||||||
.Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeColumn().Element(x => GenerateStructure(x, level));
|
|
||||||
row.RelativeColumn().Element(x => GenerateStructure(x, level));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Border(level / 10f)
|
|
||||||
.BorderColor(Colors.Black)
|
|
||||||
.Stack(stack =>
|
|
||||||
{
|
|
||||||
stack.Item().Element(x => GenerateStructure(x, level));
|
|
||||||
stack.Item().Element(x => GenerateStructure(x, level));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Drawing;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
public class ContinuousPageDocument : IDocument
|
|
||||||
{
|
|
||||||
public DocumentMetadata GetMetadata() => DocumentMetadata.Default;
|
|
||||||
|
|
||||||
public void Compose(IDocumentContainer container)
|
|
||||||
{
|
|
||||||
container.Page(page =>
|
|
||||||
{
|
|
||||||
page.Margin(20);
|
|
||||||
page.ContinuousSize(150);
|
|
||||||
|
|
||||||
page.Header().Text("Header");
|
|
||||||
|
|
||||||
page.Content().PaddingVertical(10).Border(1).Padding(10).Stack(stack =>
|
|
||||||
{
|
|
||||||
foreach (var index in Enumerable.Range(1, 100))
|
|
||||||
stack.Item().Text($"Line {index}", TextStyle.Default.Color(Placeholders.Color()));
|
|
||||||
});
|
|
||||||
|
|
||||||
page.Footer().Text("Footer");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ContinuousPageExamples
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void ContinuousPage()
|
|
||||||
{
|
|
||||||
var path = "example.pdf";
|
|
||||||
new ContinuousPageDocument().GeneratePdf(path);
|
|
||||||
Process.Start("explorer", path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
public class DebuggingTesting
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void Stack()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(500, 360)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background(Colors.White)
|
|
||||||
.Padding(15)
|
|
||||||
.Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Spacing(15);
|
|
||||||
|
|
||||||
grid.Item().Background(Colors.Grey.Medium).Text(Placeholders.LoremIpsum());
|
|
||||||
grid.Item().DebugPointer("Test").Background(Colors.Grey.Lighten1).Height(1000); // <-- problem
|
|
||||||
grid.Item().Background(Colors.Grey.Lighten2).Height(150);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
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));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,834 +1,169 @@
|
|||||||
using System.Linq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
using QuestPDF.Examples.Engine;
|
||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
using QuestPDF.Helpers;
|
using QuestPDF.Helpers;
|
||||||
using QuestPDF.Infrastructure;
|
using QuestPDF.Infrastructure;
|
||||||
using SkiaSharp;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
namespace QuestPDF.Examples
|
||||||
{
|
{
|
||||||
[TestFixture]
|
public class ElementExamples : ExampleTestBase
|
||||||
public class ElementExamples
|
|
||||||
{
|
{
|
||||||
[Test]
|
//[ShowResult]
|
||||||
public void Placeholder()
|
[ImageSize(200, 150)]
|
||||||
|
public void Placeholder(IContainer container)
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Background("#FFF")
|
||||||
.PageSize(200, 150)
|
.Padding(25)
|
||||||
.Render(container =>
|
.Placeholder();
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background("#FFF")
|
|
||||||
.Padding(25)
|
|
||||||
.Placeholder();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
//[ShowResult]
|
||||||
public void Decoration()
|
[ImageSize(300, 300)]
|
||||||
|
public void Section(IContainer container)
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Background("#FFF")
|
||||||
.PageSize(300, 300)
|
.Padding(25)
|
||||||
.Render(container =>
|
.Section(section =>
|
||||||
{
|
{
|
||||||
container
|
section
|
||||||
.Background("#FFF")
|
.Header()
|
||||||
.Padding(25)
|
.Background("#888")
|
||||||
.Decoration(decoration =>
|
|
||||||
{
|
|
||||||
decoration
|
|
||||||
.Header()
|
|
||||||
.Background(Colors.Grey.Medium)
|
|
||||||
.Padding(10)
|
|
||||||
.Text("Notes", TextStyle.Default.Size(16).Color("#FFF"));
|
|
||||||
|
|
||||||
decoration
|
|
||||||
.Content()
|
|
||||||
.Background(Colors.Grey.Lighten3)
|
|
||||||
.Padding(10)
|
|
||||||
.ExtendVertical()
|
|
||||||
.Text(Helpers.Placeholders.LoremIpsum());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Row()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(740, 200)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background("#FFF")
|
|
||||||
.Padding(20)
|
|
||||||
.Stack(stack =>
|
|
||||||
{
|
|
||||||
stack.Item()
|
|
||||||
.PaddingBottom(10)
|
|
||||||
.AlignCenter()
|
|
||||||
.Text("This Row element is 700pt wide");
|
|
||||||
|
|
||||||
stack.Item().Row(row =>
|
|
||||||
{
|
|
||||||
row.ConstantColumn(100)
|
|
||||||
.Background(Colors.Grey.Lighten1)
|
|
||||||
.Padding(10)
|
|
||||||
.ExtendVertical()
|
|
||||||
.Text("This column is 100 pt wide");
|
|
||||||
|
|
||||||
row.RelativeColumn()
|
|
||||||
.Background(Colors.Grey.Lighten2)
|
|
||||||
.Padding(10)
|
|
||||||
.Text("This column takes 1/3 of the available space (200pt)");
|
|
||||||
|
|
||||||
row.RelativeColumn(2)
|
|
||||||
.Background(Colors.Grey.Lighten3)
|
|
||||||
.Padding(10)
|
|
||||||
.Text("This column takes 2/3 of the available space (400pt)");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void RowSpacing()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(740, 200)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background("#FFF")
|
|
||||||
.Padding(20)
|
|
||||||
.Row(row =>
|
|
||||||
{
|
|
||||||
row.Spacing(20);
|
|
||||||
row.RelativeColumn(2).Border(1).Background(Colors.Grey.Lighten1);
|
|
||||||
row.RelativeColumn(3).Border(1).Background(Colors.Grey.Lighten2);
|
|
||||||
row.RelativeColumn(4).Border(1).Background(Colors.Grey.Lighten3);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Stack()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(500, 360)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background("#FFF")
|
|
||||||
.Padding(15)
|
|
||||||
.Stack(stack =>
|
|
||||||
{
|
|
||||||
stack.Spacing(15);
|
|
||||||
|
|
||||||
stack.Item().Background(Colors.Grey.Medium).Height(50);
|
|
||||||
stack.Item().Background(Colors.Grey.Lighten1).Height(100);
|
|
||||||
stack.Item().Background(Colors.Grey.Lighten2).Height(150);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Debug()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(210, 210)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(25)
|
|
||||||
.DebugArea("Grid example", Colors.Blue.Medium)
|
|
||||||
.Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Columns(3);
|
|
||||||
grid.Spacing(5);
|
|
||||||
|
|
||||||
foreach (var _ in Enumerable.Range(0, 8))
|
|
||||||
grid.Item().Height(50).Placeholder();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ElementEnd()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 200)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
var text = "";
|
|
||||||
|
|
||||||
container
|
|
||||||
.Padding(10)
|
.Padding(10)
|
||||||
.Element(x =>
|
.Text("Notes", TextStyle.Default.Size(16).Color("#FFF"));
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(text))
|
|
||||||
x.Height(10).Width(50).Background("#DDD");
|
|
||||||
else
|
|
||||||
x.Text(text);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
section
|
||||||
public void GridExample()
|
.Content()
|
||||||
{
|
.Background("#DDD")
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(400, 230)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
var textStyle = TextStyle.Default.Size(14);
|
|
||||||
|
|
||||||
container
|
|
||||||
.Padding(15)
|
|
||||||
.AlignRight()
|
|
||||||
.Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.VerticalSpacing(10);
|
|
||||||
grid.HorizontalSpacing(10);
|
|
||||||
grid.AlignCenter();
|
|
||||||
grid.Columns(10); // 12 by default
|
|
||||||
|
|
||||||
grid.Item(6).Background(Colors.Blue.Lighten1).Height(50);
|
|
||||||
grid.Item(4).Background(Colors.Blue.Lighten3).Height(50);
|
|
||||||
|
|
||||||
grid.Item(2).Background(Colors.Teal.Lighten1).Height(70);
|
|
||||||
grid.Item(3).Background(Colors.Teal.Lighten2).Height(70);
|
|
||||||
grid.Item(5).Background(Colors.Teal.Lighten3).Height(70);
|
|
||||||
|
|
||||||
grid.Item(2).Background(Colors.Green.Lighten1).Height(50);
|
|
||||||
grid.Item(2).Background(Colors.Green.Lighten2).Height(50);
|
|
||||||
grid.Item(2).Background(Colors.Green.Lighten3).Height(50);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Canvas()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 200)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background("#FFF")
|
|
||||||
.Padding(25)
|
|
||||||
.Canvas((canvas, size) =>
|
|
||||||
{
|
|
||||||
using var paint = new SKPaint
|
|
||||||
{
|
|
||||||
Color = SKColors.Red,
|
|
||||||
StrokeWidth = 10,
|
|
||||||
IsStroke = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// move origin to the center of the available space
|
|
||||||
canvas.Translate(size.Width / 2, size.Height / 2);
|
|
||||||
|
|
||||||
// draw a circle
|
|
||||||
canvas.DrawCircle(0, 0, 50, paint);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void LayersExample()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(400, 250)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(25)
|
|
||||||
.Layers(layers =>
|
|
||||||
{
|
|
||||||
// layer below main content
|
|
||||||
layers
|
|
||||||
.Layer()
|
|
||||||
.Height(100)
|
|
||||||
.Width(100)
|
|
||||||
.Background(Colors.Grey.Lighten3);
|
|
||||||
|
|
||||||
layers
|
|
||||||
.PrimaryLayer()
|
|
||||||
.Padding(25)
|
|
||||||
.Stack(stack =>
|
|
||||||
{
|
|
||||||
stack.Spacing(5);
|
|
||||||
|
|
||||||
foreach (var _ in Enumerable.Range(0, 7))
|
|
||||||
stack.Item().Text(Placeholders.Sentence());
|
|
||||||
});
|
|
||||||
|
|
||||||
// layer above the main content
|
|
||||||
layers
|
|
||||||
.Layer()
|
|
||||||
.AlignCenter()
|
|
||||||
.AlignMiddle()
|
|
||||||
.Text("Watermark", TextStyle.Default.Size(48).Bold().Color(Colors.Green.Lighten3));
|
|
||||||
|
|
||||||
layers
|
|
||||||
.Layer()
|
|
||||||
.AlignBottom()
|
|
||||||
.Text(text => text.CurrentPageNumber(TextStyle.Default.Size(16).Color(Colors.Green.Medium)));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// [Test]
|
|
||||||
// public void EnsureSpace()
|
|
||||||
// {
|
|
||||||
// RenderingTest
|
|
||||||
// .Create()
|
|
||||||
// .PageSize(300, 400)
|
|
||||||
// .Render(container =>
|
|
||||||
// {
|
|
||||||
// container
|
|
||||||
// .Padding(50)
|
|
||||||
// .Page(page =>
|
|
||||||
// {
|
|
||||||
// page.Header().PageNumber("Page {pdf:currentPage}");
|
|
||||||
//
|
|
||||||
// page.Content().Height(300).Stack(content =>
|
|
||||||
// {
|
|
||||||
// content.Item().Height(200).Background(Colors.Grey.Lighten2);
|
|
||||||
//
|
|
||||||
// content.Item().EnsureSpace(100).Stack(stack =>
|
|
||||||
// {
|
|
||||||
// stack.Spacing(10);
|
|
||||||
//
|
|
||||||
// foreach (var _ in Enumerable.Range(0, 4))
|
|
||||||
// stack.Item().Height(50).Background(Colors.Green.Lighten1);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void RandomColorMatrix()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 300)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(25)
|
|
||||||
.Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Columns(5);
|
|
||||||
|
|
||||||
Enumerable
|
|
||||||
.Range(0, 25)
|
|
||||||
.Select(x => Placeholders.BackgroundColor())
|
|
||||||
.ToList()
|
|
||||||
.ForEach(x => grid.Item().Height(50).Background(x));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DefinedColors()
|
|
||||||
{
|
|
||||||
var colors = new[]
|
|
||||||
{
|
|
||||||
Colors.Green.Darken4,
|
|
||||||
Colors.Green.Darken3,
|
|
||||||
Colors.Green.Darken2,
|
|
||||||
Colors.Green.Darken1,
|
|
||||||
|
|
||||||
Colors.Green.Medium,
|
|
||||||
|
|
||||||
Colors.Green.Lighten1,
|
|
||||||
Colors.Green.Lighten2,
|
|
||||||
Colors.Green.Lighten3,
|
|
||||||
Colors.Green.Lighten4,
|
|
||||||
Colors.Green.Lighten5,
|
|
||||||
|
|
||||||
Colors.Green.Accent1,
|
|
||||||
Colors.Green.Accent2,
|
|
||||||
Colors.Green.Accent3,
|
|
||||||
Colors.Green.Accent4,
|
|
||||||
};
|
|
||||||
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(450, 150)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(25)
|
|
||||||
.Height(100)
|
|
||||||
.Row(row =>
|
|
||||||
{
|
|
||||||
foreach (var color in colors)
|
|
||||||
row.RelativeColumn().Background(color);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DefinedFonts()
|
|
||||||
{
|
|
||||||
var fonts = new[]
|
|
||||||
{
|
|
||||||
Fonts.Calibri,
|
|
||||||
Fonts.Candara,
|
|
||||||
Fonts.Arial,
|
|
||||||
Fonts.TimesNewRoman,
|
|
||||||
Fonts.Consolas,
|
|
||||||
Fonts.Tahoma,
|
|
||||||
Fonts.Impact,
|
|
||||||
Fonts.Trebuchet,
|
|
||||||
Fonts.ComicSans
|
|
||||||
};
|
|
||||||
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(500, 175)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(25)
|
|
||||||
.Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Columns(3);
|
|
||||||
|
|
||||||
foreach (var font in fonts)
|
|
||||||
{
|
|
||||||
grid.Item()
|
|
||||||
.Border(1)
|
|
||||||
.BorderColor(Colors.Grey.Medium)
|
|
||||||
.Padding(10)
|
|
||||||
.Text(font, TextStyle.Default.FontType(font).Size(16));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Layers()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 300)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background("#FFF")
|
|
||||||
.Padding(25)
|
|
||||||
.Layers(layers =>
|
|
||||||
{
|
|
||||||
layers.Layer().Text("Something else");
|
|
||||||
|
|
||||||
layers.PrimaryLayer().Stack(stack =>
|
|
||||||
{
|
|
||||||
stack.Item().PaddingTop(20).Text("Text 1");
|
|
||||||
stack.Item().PaddingTop(40).Text("Text 2");
|
|
||||||
});
|
|
||||||
|
|
||||||
layers.Layer().Canvas((canvas, size) =>
|
|
||||||
{
|
|
||||||
using var paint = new SKPaint
|
|
||||||
{
|
|
||||||
Color = SKColors.Red,
|
|
||||||
StrokeWidth = 5
|
|
||||||
};
|
|
||||||
|
|
||||||
canvas.Translate(size.Width / 2, size.Height / 2);
|
|
||||||
canvas.DrawCircle(0, 0, 50, paint);
|
|
||||||
});
|
|
||||||
|
|
||||||
layers.Layer().Background("#8F00").Extend();
|
|
||||||
layers.Layer().PaddingTop(40).Text("It works!", TextStyle.Default.Size(24));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Box()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 150)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background("#FFF")
|
|
||||||
.Padding(15)
|
|
||||||
.Border(4)
|
|
||||||
.BorderColor(Colors.Blue.Medium)
|
|
||||||
//.Box()
|
|
||||||
.Background(Colors.Grey.Lighten2)
|
|
||||||
.Padding(15)
|
|
||||||
.Text("Test of the \n box element", TextStyle.Default.Size(20));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Scale()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 175)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Background(Colors.White)
|
|
||||||
.Padding(10)
|
.Padding(10)
|
||||||
.Decoration(decoration =>
|
.ExtendVertical()
|
||||||
{
|
.Text(TextPlaceholder.LoremIpsum());
|
||||||
var headerFontStyle = TextStyle
|
|
||||||
.Default
|
|
||||||
.Size(20)
|
|
||||||
.Color(Colors.Blue.Darken2)
|
|
||||||
.SemiBold();
|
|
||||||
|
|
||||||
decoration
|
|
||||||
.Header()
|
|
||||||
.PaddingBottom(10)
|
|
||||||
.Text("Example: scale component", headerFontStyle);
|
|
||||||
|
|
||||||
decoration
|
|
||||||
.Content()
|
|
||||||
.Stack(stack =>
|
|
||||||
{
|
|
||||||
var scales = new[] { 0.8f, 0.9f, 1.1f, 1.2f };
|
|
||||||
|
|
||||||
foreach (var scale in scales)
|
|
||||||
{
|
|
||||||
var fontColor = scale <= 1f
|
|
||||||
? Colors.Red.Lighten4
|
|
||||||
: Colors.Green.Lighten4;
|
|
||||||
|
|
||||||
var fontStyle = TextStyle.Default.Size(16);
|
|
||||||
|
|
||||||
stack
|
|
||||||
.Item()
|
|
||||||
.Border(1)
|
|
||||||
.Background(fontColor)
|
|
||||||
.Scale(scale)
|
|
||||||
.Padding(5)
|
|
||||||
.Text($"Content with {scale} scale.", fontStyle);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
//[ShowResult]
|
||||||
public void Translate()
|
[ImageSize(298, 421)]
|
||||||
|
public void Page(IContainer container)
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Background("#FFF")
|
||||||
.PageSize(300, 200)
|
.Padding(15)
|
||||||
.Render(container =>
|
.Page(page =>
|
||||||
{
|
{
|
||||||
container
|
page.Header()
|
||||||
.Background("#FFF")
|
.Height(60)
|
||||||
.Box()
|
.Background("#BBB")
|
||||||
|
|
||||||
.Padding(25)
|
|
||||||
|
|
||||||
.Background(Colors.Green.Lighten3)
|
|
||||||
|
|
||||||
.TranslateX(15)
|
|
||||||
.TranslateY(15)
|
|
||||||
|
|
||||||
.Border(2)
|
|
||||||
.BorderColor(Colors.Green.Darken1)
|
|
||||||
|
|
||||||
.Padding(50)
|
|
||||||
.Text("Moved text", TextStyle.Default.Size(25));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ConstrainedRotate()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(650, 450)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(20)
|
|
||||||
.Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Columns(2);
|
|
||||||
grid.Spacing(10);
|
|
||||||
|
|
||||||
foreach (var turns in Enumerable.Range(0, 4))
|
|
||||||
{
|
|
||||||
grid.Item()
|
|
||||||
.Width(300)
|
|
||||||
.Height(200)
|
|
||||||
.Background(Colors.Grey.Lighten2)
|
|
||||||
.Padding(10)
|
|
||||||
.Element(element =>
|
|
||||||
{
|
|
||||||
foreach (var x in Enumerable.Range(0, turns))
|
|
||||||
element = element.RotateRight();
|
|
||||||
|
|
||||||
return element;
|
|
||||||
})
|
|
||||||
.Box()
|
|
||||||
.Background(Colors.White)
|
|
||||||
.Padding(10)
|
|
||||||
.Text($"Rotated {turns * 90}°", TextStyle.Default.Size(16));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void FreeRotate()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 300)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(25)
|
|
||||||
.Background(Colors.Grey.Lighten2)
|
|
||||||
|
|
||||||
.AlignCenter()
|
.AlignCenter()
|
||||||
.AlignMiddle()
|
.AlignMiddle()
|
||||||
|
.Text("Header");
|
||||||
|
|
||||||
|
page.Content()
|
||||||
.Background(Colors.White)
|
.Background("#DDD")
|
||||||
|
|
||||||
.Rotate(30)
|
|
||||||
|
|
||||||
.Width(100)
|
|
||||||
.Height(100)
|
|
||||||
.Background(Colors.Blue.Medium);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void FreeRotateCenter()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(300, 300)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(25)
|
|
||||||
.Background(Colors.Grey.Lighten2)
|
|
||||||
|
|
||||||
.AlignCenter()
|
.AlignCenter()
|
||||||
.AlignMiddle()
|
.AlignMiddle()
|
||||||
|
.Text("Content");
|
||||||
|
|
||||||
.Background(Colors.White)
|
page.Footer()
|
||||||
|
.Height(30)
|
||||||
.TranslateX(50)
|
.Background("#BBB")
|
||||||
.TranslateY(50)
|
.AlignCenter()
|
||||||
|
.AlignMiddle()
|
||||||
.Rotate(30)
|
.Text("Footer");
|
||||||
|
|
||||||
.TranslateX(-50)
|
|
||||||
.TranslateY(-50)
|
|
||||||
|
|
||||||
.Width(100)
|
|
||||||
.Height(100)
|
|
||||||
.Background(Colors.Blue.Medium);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
//[ShowResult]
|
||||||
public void Flip()
|
[ImageSize(740, 200)]
|
||||||
|
public void Row(IContainer container)
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Background("#FFF")
|
||||||
.PageSize(350, 350)
|
.Padding(20)
|
||||||
.Render(container =>
|
.Stack(stack =>
|
||||||
{
|
{
|
||||||
container
|
stack.Element()
|
||||||
.Padding(20)
|
.PaddingBottom(10)
|
||||||
.Grid(grid =>
|
.AlignCenter()
|
||||||
{
|
.Text("This Row element is 700pt wide");
|
||||||
grid.Columns(2);
|
|
||||||
grid.Spacing(10);
|
|
||||||
|
|
||||||
foreach (var turns in Enumerable.Range(0, 4))
|
stack.Element().Row(row =>
|
||||||
{
|
{
|
||||||
grid.Item()
|
row.ConstantColumn(100)
|
||||||
.Width(150)
|
.Background("#DDD")
|
||||||
.Height(150)
|
.Padding(10)
|
||||||
.Background(Colors.Grey.Lighten3)
|
.ExtendVertical()
|
||||||
.Padding(10)
|
.Text("This column is 100 pt wide");
|
||||||
.Element(element =>
|
|
||||||
{
|
|
||||||
if (turns == 1 || turns == 2)
|
|
||||||
element = element.FlipHorizontal();
|
|
||||||
|
|
||||||
if (turns == 2 || turns == 3)
|
row.RelativeColumn()
|
||||||
element = element.FlipVertical();
|
.Background("#BBB")
|
||||||
|
.Padding(10)
|
||||||
|
.Text("This column takes 1/3 of the available space (200pt)");
|
||||||
|
|
||||||
return element;
|
row.RelativeColumn(2)
|
||||||
})
|
.Background("#DDD")
|
||||||
.Box()
|
.Padding(10)
|
||||||
.Background(Colors.White)
|
.Text("This column takes 2/3 of the available space (400pt)");
|
||||||
.Padding(10)
|
});
|
||||||
.Text($"Flipped {turns}", TextStyle.Default.Size(16));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
//[ShowResult]
|
||||||
public void RotateInTable()
|
[ImageSize(500, 350)]
|
||||||
|
public void Column(IContainer container)
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Background("#FFF")
|
||||||
.PageSize(200, 200)
|
.Padding(15)
|
||||||
.Render(container =>
|
.Stack(column =>
|
||||||
{
|
{
|
||||||
container
|
column.Spacing(10);
|
||||||
.Padding(10)
|
|
||||||
.Border(2)
|
|
||||||
.Row(row =>
|
|
||||||
{
|
|
||||||
row.ConstantColumn(25)
|
|
||||||
.Border(1)
|
|
||||||
.RotateLeft()
|
|
||||||
.AlignCenter()
|
|
||||||
.AlignMiddle()
|
|
||||||
.Text("Sample text");
|
|
||||||
|
|
||||||
row.RelativeColumn().Border(1).Padding(5).Text(Placeholders.Paragraph());
|
column
|
||||||
});
|
.Element()
|
||||||
|
.Background("#999")
|
||||||
|
.Height(50);
|
||||||
|
|
||||||
|
column
|
||||||
|
.Element()
|
||||||
|
.Background("#BBB")
|
||||||
|
.Height(100);
|
||||||
|
|
||||||
|
column
|
||||||
|
.Element()
|
||||||
|
.Background("#DDD")
|
||||||
|
.Height(150);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
//[ShowResult]
|
||||||
public void Unconstrained()
|
[ImageSize(300, 200)]
|
||||||
|
public void Debug(IContainer container)
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Padding(25)
|
||||||
.PageSize(400, 350)
|
.Debug()
|
||||||
.Render(container =>
|
.Padding(-5)
|
||||||
|
.Row(row =>
|
||||||
{
|
{
|
||||||
container
|
row.RelativeColumn().Padding(5).Extend().Placeholder();
|
||||||
.Padding(25)
|
row.RelativeColumn().Padding(5).Extend().Placeholder();
|
||||||
.PaddingLeft(75)
|
|
||||||
.Stack(stack =>
|
|
||||||
{
|
|
||||||
stack.Item().Width(300).Height(150).Background(Colors.Blue.Lighten4);
|
|
||||||
|
|
||||||
stack
|
|
||||||
.Item()
|
|
||||||
|
|
||||||
// creates an infinite space for its child
|
|
||||||
.Unconstrained()
|
|
||||||
|
|
||||||
// moves the child up and left
|
|
||||||
.TranslateX(-50)
|
|
||||||
.TranslateY(-50)
|
|
||||||
|
|
||||||
// limits the space for the child
|
|
||||||
.Width(100)
|
|
||||||
.Height(100)
|
|
||||||
|
|
||||||
.Background(Colors.Blue.Darken1);
|
|
||||||
|
|
||||||
stack.Item().Width(300).Height(150).Background(Colors.Blue.Lighten3);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[ShowResult]
|
||||||
public void ComplexLayout()
|
[ImageSize(300, 200)]
|
||||||
|
public void ElementEnd(IContainer container)
|
||||||
{
|
{
|
||||||
RenderingTest
|
var text = "";
|
||||||
.Create()
|
|
||||||
.PageSize(500, 225)
|
container
|
||||||
.Render(container =>
|
.Padding(10)
|
||||||
|
.Element(x =>
|
||||||
{
|
{
|
||||||
container
|
if (string.IsNullOrWhiteSpace(text))
|
||||||
.Padding(25)
|
x.Height(10).Width(50).Background("#DDD");
|
||||||
.Stack(stack =>
|
else
|
||||||
{
|
x.Text(text);
|
||||||
stack.Item().Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeColumn().LabelCell("Label 1");
|
|
||||||
|
|
||||||
row.RelativeColumn(3).Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Columns(3);
|
|
||||||
|
|
||||||
grid.Item(2).LabelCell("Label 2");
|
|
||||||
grid.Item().LabelCell("Label 3");
|
|
||||||
|
|
||||||
grid.Item(2).ValueCell().Text("Value 2");
|
|
||||||
grid.Item().ValueCell().Text("Value 3");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
stack.Item().Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeColumn().ValueCell().Text("Value 1");
|
|
||||||
|
|
||||||
row.RelativeColumn(3).Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Columns(3);
|
|
||||||
|
|
||||||
grid.Item().LabelCell("Label 4");
|
|
||||||
grid.Item(2).LabelCell("Label 5");
|
|
||||||
|
|
||||||
grid.Item().ValueCell().Text("Value 4");
|
|
||||||
grid.Item(2).ValueCell().Text("Value 5");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
stack.Item().Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeColumn().LabelCell("Label 6");
|
|
||||||
row.RelativeColumn().ValueCell().Text("Value 6");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DomainSpecificLanguage()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(600, 310)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(25)
|
|
||||||
.Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Columns(10);
|
|
||||||
|
|
||||||
for(var i=1; i<=4; i++)
|
|
||||||
{
|
|
||||||
grid.Item(2).LabelCell(Placeholders.Label());
|
|
||||||
grid.Item(3).ValueCell().Image(Placeholders.Image(200, 150));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using QuestPDF.Drawing;
|
||||||
|
using QuestPDF.Elements;
|
||||||
|
using QuestPDF.Fluent;
|
||||||
|
using QuestPDF.Infrastructure;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
namespace QuestPDF.Examples.Engine
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ExampleTestBase
|
||||||
|
{
|
||||||
|
private readonly Size DefaultImageSize = new Size(400, 300);
|
||||||
|
private const string ResultPath = "Result";
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
if (Directory.Exists(ResultPath))
|
||||||
|
Directory.Delete(ResultPath, true);
|
||||||
|
|
||||||
|
Directory.CreateDirectory(ResultPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void RunTest()
|
||||||
|
{
|
||||||
|
GetType()
|
||||||
|
.GetMethods()
|
||||||
|
.Where(IsExampleMethod)
|
||||||
|
.ToList()
|
||||||
|
.ForEach(HandleExample);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsExampleMethod(MethodInfo method)
|
||||||
|
{
|
||||||
|
var parameters = method.GetParameters();
|
||||||
|
return parameters.Length == 1 && parameters.First().ParameterType == typeof(IContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private T GetAttribute<T>(MethodInfo methodInfo) where T : Attribute
|
||||||
|
{
|
||||||
|
return methodInfo.GetCustomAttributes().FirstOrDefault(y => y is T) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleExample(MethodInfo methodInfo)
|
||||||
|
{
|
||||||
|
var size = GetAttribute<ImageSizeAttribute>(methodInfo)?.Size ?? DefaultImageSize;
|
||||||
|
var fileName = GetAttribute<FileNameAttribute>(methodInfo)?.FileName ?? methodInfo.Name;
|
||||||
|
var showResult = GetAttribute<ShowResultAttribute>(methodInfo) != null;
|
||||||
|
var shouldIgnore = GetAttribute<IgnoreAttribute>(methodInfo) != null;
|
||||||
|
|
||||||
|
if (shouldIgnore)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var container = new Container();
|
||||||
|
methodInfo.Invoke(this, new object[] {container});
|
||||||
|
|
||||||
|
Func<int, string> fileNameSchema = i => $"{fileName.ToLower()}-${i}.png";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var document = new SimpleDocument(container, size);
|
||||||
|
document.GenerateImages(fileNameSchema);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new Exception($"Cannot perform test ${fileName}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showResult)
|
||||||
|
Process.Start("explorer", fileNameSchema(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] RenderPage(Element element, Size size)
|
||||||
|
{
|
||||||
|
// scale the result so it is more readable
|
||||||
|
const float scalingFactor = 2;
|
||||||
|
|
||||||
|
var imageInfo = new SKImageInfo((int)(size.Width * scalingFactor), (int)(size.Height * scalingFactor));
|
||||||
|
using var surface = SKSurface.Create(imageInfo);
|
||||||
|
surface.Canvas.Scale(scalingFactor);
|
||||||
|
|
||||||
|
var canvas = new Canvas(surface.Canvas);
|
||||||
|
element?.Draw(canvas, size);
|
||||||
|
|
||||||
|
surface.Canvas.Save();
|
||||||
|
return surface.Snapshot().Encode(SKEncodedImageFormat.Png, 100).ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace QuestPDF.Examples.Engine
|
||||||
|
{
|
||||||
|
public class FileNameAttribute : Attribute
|
||||||
|
{
|
||||||
|
public string FileName { get; }
|
||||||
|
|
||||||
|
public FileNameAttribute(string fileName)
|
||||||
|
{
|
||||||
|
FileName = fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace QuestPDF.Examples.Engine
|
||||||
|
{
|
||||||
|
public class IgnoreAttribute : Attribute
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using QuestPDF.Infrastructure;
|
||||||
|
|
||||||
|
namespace QuestPDF.Examples.Engine
|
||||||
|
{
|
||||||
|
public class ImageSizeAttribute : Attribute
|
||||||
|
{
|
||||||
|
private int Width { get; }
|
||||||
|
private int Height { get; }
|
||||||
|
|
||||||
|
public Size Size => new Size(Width, Height);
|
||||||
|
|
||||||
|
public ImageSizeAttribute(int width, int height)
|
||||||
|
{
|
||||||
|
Width = width;
|
||||||
|
Height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using QuestPDF.Elements;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples.Engine
|
|
||||||
{
|
|
||||||
public enum RenderingTestResult
|
|
||||||
{
|
|
||||||
Pdf,
|
|
||||||
Images
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RenderingTest
|
|
||||||
{
|
|
||||||
private string FileNamePrefix = "test";
|
|
||||||
private Size Size { get; set; }
|
|
||||||
private int? MaxPagesThreshold { get; set; }
|
|
||||||
private bool ShowResult { get; set; }
|
|
||||||
private RenderingTestResult ResultType { get; set; } = RenderingTestResult.Images;
|
|
||||||
|
|
||||||
private RenderingTest()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RenderingTest Create([CallerMemberName] string fileName = "test")
|
|
||||||
{
|
|
||||||
return new RenderingTest().FileName(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RenderingTest FileName(string fileName)
|
|
||||||
{
|
|
||||||
FileNamePrefix = fileName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RenderingTest PageSize(Size size)
|
|
||||||
{
|
|
||||||
Size = size;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RenderingTest PageSize(int width, int height)
|
|
||||||
{
|
|
||||||
return PageSize(new Size(width, height));
|
|
||||||
}
|
|
||||||
|
|
||||||
public RenderingTest ProducePdf()
|
|
||||||
{
|
|
||||||
ResultType = RenderingTestResult.Pdf;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RenderingTest ProduceImages()
|
|
||||||
{
|
|
||||||
ResultType = RenderingTestResult.Images;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RenderingTest ShowResults()
|
|
||||||
{
|
|
||||||
ShowResult = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Render(Action<IContainer> content)
|
|
||||||
{
|
|
||||||
RenderDocument(container =>
|
|
||||||
{
|
|
||||||
container.Page(page =>
|
|
||||||
{
|
|
||||||
page.Size(new PageSize(Size.Width, Size.Height));
|
|
||||||
page.Content().Container().Background(Colors.White).Element(content);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MaxPages(int value)
|
|
||||||
{
|
|
||||||
MaxPagesThreshold = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RenderDocument(Action<IDocumentContainer> content)
|
|
||||||
{
|
|
||||||
MaxPagesThreshold ??= ResultType == RenderingTestResult.Pdf ? 1000 : 10;
|
|
||||||
var document = new SimpleDocument(content, MaxPagesThreshold.Value);
|
|
||||||
|
|
||||||
Render(document);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Render(IDocument document)
|
|
||||||
{
|
|
||||||
if (ResultType == RenderingTestResult.Images)
|
|
||||||
{
|
|
||||||
Func<int, string> fileNameSchema = i => $"{FileNamePrefix}-${i}.png";
|
|
||||||
document.GenerateImages(fileNameSchema);
|
|
||||||
|
|
||||||
if (ShowResult)
|
|
||||||
Process.Start("explorer", fileNameSchema(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ResultType == RenderingTestResult.Pdf)
|
|
||||||
{
|
|
||||||
var fileName = $"{FileNamePrefix}.pdf";
|
|
||||||
document.GeneratePdf(fileName);
|
|
||||||
|
|
||||||
if (ShowResult)
|
|
||||||
Process.Start("explorer", fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace QuestPDF.Examples.Engine
|
||||||
|
{
|
||||||
|
public class ShowResultAttribute : Attribute
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using QuestPDF.Drawing;
|
||||||
using QuestPDF.Drawing;
|
|
||||||
using QuestPDF.Elements;
|
|
||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
using QuestPDF.Helpers;
|
using QuestPDF.Helpers;
|
||||||
using QuestPDF.Infrastructure;
|
using QuestPDF.Infrastructure;
|
||||||
@@ -9,29 +7,27 @@ namespace QuestPDF.Examples.Engine
|
|||||||
{
|
{
|
||||||
public class SimpleDocument : IDocument
|
public class SimpleDocument : IDocument
|
||||||
{
|
{
|
||||||
public const int ImageScalingFactor = 2;
|
private IContainer Container { get; }
|
||||||
|
private Size Size { get; }
|
||||||
|
|
||||||
private Action<IDocumentContainer> Content { get; }
|
public SimpleDocument(IContainer container, Size size)
|
||||||
private int MaxPages { get; }
|
|
||||||
|
|
||||||
public SimpleDocument(Action<IDocumentContainer> content, int maxPages)
|
|
||||||
{
|
{
|
||||||
Content = content;
|
Container = container;
|
||||||
MaxPages = maxPages;
|
Size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DocumentMetadata GetMetadata()
|
public DocumentMetadata GetMetadata()
|
||||||
{
|
{
|
||||||
return new DocumentMetadata()
|
return new DocumentMetadata()
|
||||||
{
|
{
|
||||||
RasterDpi = PageSizes.PointsPerInch * ImageScalingFactor,
|
RasterDpi = PageSizes.PointsPerInch * 2,
|
||||||
DocumentLayoutExceptionThreshold = MaxPages
|
Size = Size
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Compose(IDocumentContainer container)
|
public void Compose(IContainer container)
|
||||||
{
|
{
|
||||||
Content(container);
|
container.Background("#FFF").Element(Container.Child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using NUnit.Framework;
|
using System.Linq;
|
||||||
using QuestPDF.Examples.Engine;
|
using QuestPDF.Examples.Engine;
|
||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
using QuestPDF.Helpers;
|
using QuestPDF.Helpers;
|
||||||
@@ -12,39 +12,33 @@ namespace QuestPDF.Examples
|
|||||||
{
|
{
|
||||||
return container
|
return container
|
||||||
.Border(1)
|
.Border(1)
|
||||||
.Background(dark ? Colors.Grey.Lighten2 : Colors.White)
|
.Background(dark ? "#EEE" : "#FFF")
|
||||||
.Padding(10);
|
.Padding(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LabelCell(this IContainer container, string text) => container.Cell(true).Text(text, TextStyle.Default.Medium());
|
public static IContainer LabelCell(this IContainer container) => container.Cell(true);
|
||||||
public static IContainer ValueCell(this IContainer container) => container.Cell(false);
|
public static IContainer ValueCell(this IContainer container) => container.Cell(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FrameExample
|
public class FrameExample: ExampleTestBase
|
||||||
{
|
{
|
||||||
[Test]
|
[ImageSize(550, 400)]
|
||||||
public void Frame()
|
[ShowResult]
|
||||||
|
public void Frame(IContainer container)
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Background("#FFF")
|
||||||
.PageSize(550, 400)
|
.Padding(25)
|
||||||
.ShowResults()
|
.Stack(stack =>
|
||||||
.Render(container =>
|
|
||||||
{
|
{
|
||||||
container
|
for(var i=1; i<=4; i++)
|
||||||
.Background("#FFF")
|
{
|
||||||
.Padding(25)
|
stack.Element().Row(row =>
|
||||||
.Stack(stack =>
|
|
||||||
{
|
{
|
||||||
for(var i=1; i<=4; i++)
|
row.RelativeColumn(2).LabelCell().Text(TextPlaceholder.Label());
|
||||||
{
|
row.RelativeColumn(3).ValueCell().Text(TextPlaceholder.Paragraph());
|
||||||
stack.Item().Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeColumn(2).LabelCell(Placeholders.Label());
|
|
||||||
row.RelativeColumn(3).ValueCell().Text(Placeholders.Paragraph());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
using System.IO;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
public class ImageExamples
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void LoadingImage()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(PageSizes.A5)
|
|
||||||
.ProducePdf()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(page =>
|
|
||||||
{
|
|
||||||
page.Padding(25).Stack(stack =>
|
|
||||||
{
|
|
||||||
stack.Spacing(25);
|
|
||||||
|
|
||||||
stack.Item().Image("logo.png");
|
|
||||||
|
|
||||||
var binaryData = File.ReadAllBytes("logo.png");
|
|
||||||
stack.Item().Image(binaryData);
|
|
||||||
|
|
||||||
using var stream = new FileStream("logo.png", FileMode.Open);
|
|
||||||
stack.Item().Image(stream);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Exception()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(PageSizes.A5)
|
|
||||||
.ProducePdf()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(page => page.Image("non_existent.png"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection.Metadata.Ecma335;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
public class InlinedExamples
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void Inlined()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(800, 650)
|
|
||||||
.ProduceImages()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(25)
|
|
||||||
.Decoration(decoration =>
|
|
||||||
{
|
|
||||||
decoration.Header().Text(text =>
|
|
||||||
{
|
|
||||||
text.DefaultTextStyle(TextStyle.Default.Size(20));
|
|
||||||
|
|
||||||
text.CurrentPageNumber();
|
|
||||||
text.Span(" / ");
|
|
||||||
text.TotalPages();
|
|
||||||
});
|
|
||||||
|
|
||||||
decoration
|
|
||||||
.Content()
|
|
||||||
.PaddingTop(25)
|
|
||||||
//.Box()
|
|
||||||
.Border(1)
|
|
||||||
.Background(Colors.Grey.Lighten2)
|
|
||||||
.Inlined(inlined =>
|
|
||||||
{
|
|
||||||
inlined.Spacing(25);
|
|
||||||
|
|
||||||
inlined.AlignSpaceAround();
|
|
||||||
inlined.BaselineMiddle();
|
|
||||||
|
|
||||||
var random = new Random(123);
|
|
||||||
|
|
||||||
foreach (var _ in Enumerable.Range(0, 50))
|
|
||||||
{
|
|
||||||
var width = random.Next(2, 7);
|
|
||||||
var height = random.Next(2, 7);
|
|
||||||
|
|
||||||
var sizeText = $"{width}×{height}";
|
|
||||||
|
|
||||||
inlined
|
|
||||||
.Item()
|
|
||||||
.Border(1)
|
|
||||||
.Width(width * 25)
|
|
||||||
.Height(height * 25)
|
|
||||||
.Background(Placeholders.BackgroundColor())
|
|
||||||
.Layers(layers =>
|
|
||||||
{
|
|
||||||
layers.Layer().Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Columns(width);
|
|
||||||
Enumerable.Range(0, width * height).ToList().ForEach(x => grid.Item().Border(1).BorderColor(Colors.White).Width(25).Height(25));
|
|
||||||
});
|
|
||||||
|
|
||||||
layers
|
|
||||||
.PrimaryLayer()
|
|
||||||
.AlignCenter()
|
|
||||||
.AlignMiddle()
|
|
||||||
.Text(sizeText, TextStyle.Default.Size(15));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Inline_AlignLeft_BaselineBottom()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(800, 600)
|
|
||||||
.ProduceImages()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(20)
|
|
||||||
.Box()
|
|
||||||
.Border(1)
|
|
||||||
.Background(Colors.Grey.Lighten4)
|
|
||||||
.Inlined(inlined =>
|
|
||||||
{
|
|
||||||
inlined.VerticalSpacing(50);
|
|
||||||
inlined.HorizontalSpacing(25);
|
|
||||||
inlined.AlignRight();
|
|
||||||
inlined.BaselineMiddle();
|
|
||||||
|
|
||||||
foreach (var _ in Enumerable.Range(0, 100))
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
using QuestPDF.Examples.Engine;
|
||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
using QuestPDF.Infrastructure;
|
using QuestPDF.Infrastructure;
|
||||||
@@ -28,32 +27,27 @@ namespace QuestPDF.Examples
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LoremPicsumExample
|
public class LoremPicsumExample : ExampleTestBase
|
||||||
{
|
{
|
||||||
[Test]
|
[ShowResult]
|
||||||
public void LoremPicsum()
|
[ImageSize(350, 280)]
|
||||||
|
public void LoremPicsum(IContainer container)
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Background("#FFF")
|
||||||
.PageSize(350, 280)
|
.Padding(25)
|
||||||
.Render(container =>
|
.Stack(column =>
|
||||||
{
|
{
|
||||||
container
|
column.Spacing(10);
|
||||||
.Background("#FFF")
|
|
||||||
.Padding(25)
|
|
||||||
.Stack(column =>
|
|
||||||
{
|
|
||||||
column.Spacing(10);
|
|
||||||
|
|
||||||
column
|
column
|
||||||
.Item()
|
.Element()
|
||||||
.Component(new LoremPicsum(true));
|
.Component(new LoremPicsum(true));
|
||||||
|
|
||||||
column
|
column
|
||||||
.Item()
|
.Element()
|
||||||
.AlignRight()
|
.AlignRight()
|
||||||
.Text("From Lorem Picsum");
|
.Text("From Lorem Picsum");
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,163 +1,132 @@
|
|||||||
using NUnit.Framework;
|
using QuestPDF.Examples.Engine;
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
using QuestPDF.Infrastructure;
|
using QuestPDF.Infrastructure;
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
namespace QuestPDF.Examples
|
||||||
{
|
{
|
||||||
public class Examples
|
public class Examples : ExampleTestBase
|
||||||
{
|
{
|
||||||
[Test]
|
public void Padding(IContainer container)
|
||||||
public void Padding()
|
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Background("#FDD")
|
||||||
.PageSize(300, 300)
|
.Padding(50)
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
.Background("#AFA")
|
||||||
|
.PaddingVertical(50)
|
||||||
|
|
||||||
|
.Background("#77F")
|
||||||
|
.PaddingHorizontal(50)
|
||||||
|
|
||||||
|
.Background("#444");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Border(IContainer container)
|
||||||
|
{
|
||||||
|
container
|
||||||
|
.Background("#EEE")
|
||||||
|
.Padding(25)
|
||||||
|
|
||||||
|
.AlignBottom()
|
||||||
|
.AlignCenter()
|
||||||
|
.BorderBottom(2)
|
||||||
|
.BorderColor("#000")
|
||||||
|
|
||||||
|
.Background("FFF")
|
||||||
|
.Padding(5)
|
||||||
|
.Text("Sample text", TextStyle.Default.FontType("Segoe UI emoji").Alignment(HorizontalAlignment.Center));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Alignment(IContainer container)
|
||||||
|
{
|
||||||
|
container
|
||||||
|
.Stack(column =>
|
||||||
{
|
{
|
||||||
container
|
column
|
||||||
.Background("#FDD")
|
.Element()
|
||||||
.Padding(50)
|
.Height(100)
|
||||||
|
.Background("#FFF")
|
||||||
|
|
||||||
.Background("#AFA")
|
.AlignLeft()
|
||||||
.PaddingVertical(50)
|
.AlignMiddle()
|
||||||
|
|
||||||
.Background("#77F")
|
|
||||||
.PaddingHorizontal(50)
|
|
||||||
|
|
||||||
|
.Width(50)
|
||||||
|
.Height(50)
|
||||||
.Background("#444");
|
.Background("#444");
|
||||||
|
|
||||||
|
column
|
||||||
|
.Element()
|
||||||
|
.Height(100)
|
||||||
|
.Background("#DDD")
|
||||||
|
|
||||||
|
.AlignCenter()
|
||||||
|
.AlignMiddle()
|
||||||
|
|
||||||
|
.Width(50)
|
||||||
|
.Height(50)
|
||||||
|
.Background("#222");
|
||||||
|
|
||||||
|
column
|
||||||
|
.Element()
|
||||||
|
.Height(100)
|
||||||
|
.Background("#BBB")
|
||||||
|
|
||||||
|
.AlignRight()
|
||||||
|
.AlignMiddle()
|
||||||
|
|
||||||
|
.Width(50)
|
||||||
|
.Height(50)
|
||||||
|
.Background("#000");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
public void Expand(IContainer container)
|
||||||
public void Border()
|
|
||||||
{
|
{
|
||||||
RenderingTest
|
container
|
||||||
.Create()
|
.Stack(column =>
|
||||||
.PageSize(200, 150)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
{
|
||||||
container
|
column
|
||||||
.Background("#EEE")
|
.Element()
|
||||||
.Padding(25)
|
.Height(150)
|
||||||
|
.Row(row =>
|
||||||
.AlignBottom()
|
|
||||||
.AlignCenter()
|
|
||||||
.BorderBottom(2)
|
|
||||||
.BorderColor("#000")
|
|
||||||
|
|
||||||
.Background("FFF")
|
|
||||||
.Padding(5)
|
|
||||||
.AlignCenter()
|
|
||||||
.Text("Sample text", TextStyle.Default.FontType("Segoe UI emoji"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Alignment()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(200, 150)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Stack(column =>
|
|
||||||
{
|
{
|
||||||
column
|
row.RelativeColumn()
|
||||||
.Item()
|
.Extend()
|
||||||
.Height(100)
|
.Background("FFF")
|
||||||
.Background("#FFF")
|
|
||||||
|
|
||||||
.AlignLeft()
|
|
||||||
.AlignMiddle()
|
|
||||||
|
|
||||||
.Width(50)
|
|
||||||
.Height(50)
|
.Height(50)
|
||||||
.Background("#444");
|
|
||||||
|
|
||||||
column
|
|
||||||
.Item()
|
|
||||||
.Height(100)
|
|
||||||
.Background("#DDD")
|
|
||||||
|
|
||||||
.AlignCenter()
|
|
||||||
.AlignMiddle()
|
|
||||||
|
|
||||||
.Width(50)
|
.Width(50)
|
||||||
|
.Background("444");
|
||||||
|
|
||||||
|
row.RelativeColumn()
|
||||||
|
.Extend()
|
||||||
|
.Background("BBB")
|
||||||
|
|
||||||
.Height(50)
|
.Height(50)
|
||||||
.Background("#222");
|
.ExtendHorizontal()
|
||||||
|
.Background("444");
|
||||||
column
|
|
||||||
.Item()
|
|
||||||
.Height(100)
|
|
||||||
.Background("#BBB")
|
|
||||||
|
|
||||||
.AlignRight()
|
|
||||||
.AlignMiddle()
|
|
||||||
|
|
||||||
.Width(50)
|
|
||||||
.Height(50)
|
|
||||||
.Background("#000");
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
column
|
||||||
public void Expand()
|
.Element()
|
||||||
{
|
.Height(150)
|
||||||
RenderingTest
|
.Row(row =>
|
||||||
.Create()
|
|
||||||
.PageSize(200, 150)
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Stack(column =>
|
|
||||||
{
|
{
|
||||||
column
|
row.RelativeColumn()
|
||||||
.Item()
|
.Extend()
|
||||||
.Height(150)
|
.Background("BBB")
|
||||||
.Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeColumn()
|
|
||||||
.Extend()
|
|
||||||
.Background("FFF")
|
|
||||||
|
|
||||||
.Height(50)
|
.ExtendVertical()
|
||||||
.Width(50)
|
.Width(50)
|
||||||
.Background("444");
|
.Background("444");
|
||||||
|
|
||||||
row.RelativeColumn()
|
row.RelativeColumn()
|
||||||
.Extend()
|
.Extend()
|
||||||
.Background("BBB")
|
.Background("BBB")
|
||||||
|
|
||||||
.Height(50)
|
.ExtendVertical()
|
||||||
.ExtendHorizontal()
|
.ExtendHorizontal()
|
||||||
.Background("444");
|
.Background("444");
|
||||||
});
|
|
||||||
|
|
||||||
column
|
|
||||||
.Item()
|
|
||||||
.Height(150)
|
|
||||||
.Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeColumn()
|
|
||||||
.Extend()
|
|
||||||
.Background("BBB")
|
|
||||||
|
|
||||||
.ExtendVertical()
|
|
||||||
.Width(50)
|
|
||||||
.Background("444");
|
|
||||||
|
|
||||||
row.RelativeColumn()
|
|
||||||
.Extend()
|
|
||||||
.Background("BBB")
|
|
||||||
|
|
||||||
.ExtendVertical()
|
|
||||||
.ExtendHorizontal()
|
|
||||||
.Background("444");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,27 +6,14 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="microcharts" Version="0.9.5.9" />
|
<PackageReference Include="nunit" Version="3.12.0" />
|
||||||
<PackageReference Include="nunit" Version="3.13.2" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||||
<PackageReference Include="SkiaSharp" Version="2.80.3" />
|
<PackageReference Include="SkiaSharp" Version="2.80.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\QuestPDF\QuestPDF.csproj" />
|
<ProjectReference Include="..\QuestPDF\QuestPDF.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="quo-vadis.txt">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="LibreBarcode39-Regular.ttf">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="logo.png">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,226 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
public class TextBenchmark
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void Generate()
|
|
||||||
{
|
|
||||||
var chapters = GetBookChapters().ToList();
|
|
||||||
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(PageSizes.A4)
|
|
||||||
.ProducePdf()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(x => ComposeBook(x, chapters));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Benchmark()
|
|
||||||
{
|
|
||||||
var chapters = GetBookChapters().ToList();
|
|
||||||
|
|
||||||
var results = PerformTest(16).ToList();
|
|
||||||
|
|
||||||
Console.WriteLine($"Min: {results.Min():F}");
|
|
||||||
Console.WriteLine($"Max: {results.Max():F}");
|
|
||||||
Console.WriteLine($"Avg: {results.Average():F}");
|
|
||||||
|
|
||||||
void GenerateDocument()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(PageSizes.A4)
|
|
||||||
.ProducePdf()
|
|
||||||
.Render(x => ComposeBook(x, chapters));
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerable<float> PerformTest(int attempts)
|
|
||||||
{
|
|
||||||
foreach (var i in Enumerable.Range(0, attempts))
|
|
||||||
{
|
|
||||||
var timer = new Stopwatch();
|
|
||||||
|
|
||||||
timer.Start();
|
|
||||||
GenerateDocument();
|
|
||||||
timer.Stop();
|
|
||||||
|
|
||||||
Console.WriteLine($"Attempt {i}: {timer.ElapsedMilliseconds:F}");
|
|
||||||
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).Where(x => !string.IsNullOrWhiteSpace(x));
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(50)
|
|
||||||
.Decoration(decoration =>
|
|
||||||
{
|
|
||||||
decoration
|
|
||||||
.Content()
|
|
||||||
.Stack(stack =>
|
|
||||||
{
|
|
||||||
stack.Item().Element(Title);
|
|
||||||
stack.Item().PageBreak();
|
|
||||||
stack.Item().Element(TableOfContents);
|
|
||||||
stack.Item().PageBreak();
|
|
||||||
|
|
||||||
Chapters(stack);
|
|
||||||
|
|
||||||
stack.Item().Element(Acknowledgements);
|
|
||||||
});
|
|
||||||
|
|
||||||
decoration.Footer().Element(Footer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void Title(IContainer container)
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Extend()
|
|
||||||
.PaddingBottom(200)
|
|
||||||
.AlignBottom()
|
|
||||||
.Stack(stack =>
|
|
||||||
{
|
|
||||||
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));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void TableOfContents(IContainer container)
|
|
||||||
{
|
|
||||||
container.Stack(stack =>
|
|
||||||
{
|
|
||||||
SectionTitle(stack, "Spis treści");
|
|
||||||
|
|
||||||
foreach (var chapter in chapters)
|
|
||||||
{
|
|
||||||
stack.Item().InternalLink(chapter.Title).Row(row =>
|
|
||||||
{
|
|
||||||
row.RelativeColumn().Text(chapter.Title, normalStyle);
|
|
||||||
row.ConstantColumn(100).AlignRight().Text(text => text.PageNumberOfLocation(chapter.Title, normalStyle));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void Chapters(StackDescriptor stack)
|
|
||||||
{
|
|
||||||
foreach (var chapter in chapters)
|
|
||||||
{
|
|
||||||
stack.Item().Element(container => Chapter(container, chapter.Title, chapter.Content));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Chapter(IContainer container, string title, string content)
|
|
||||||
{
|
|
||||||
container.Stack(stack =>
|
|
||||||
{
|
|
||||||
SectionTitle(stack, title);
|
|
||||||
|
|
||||||
stack.Item().Text(text =>
|
|
||||||
{
|
|
||||||
text.ParagraphSpacing(5);
|
|
||||||
text.Span(content, normalStyle);
|
|
||||||
});
|
|
||||||
|
|
||||||
stack.Item().PageBreak();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void Acknowledgements(IContainer container)
|
|
||||||
{
|
|
||||||
container.Stack(stack =>
|
|
||||||
{
|
|
||||||
SectionTitle(stack, "Podziękowania");
|
|
||||||
|
|
||||||
stack.Item().Text(text =>
|
|
||||||
{
|
|
||||||
text.DefaultTextStyle(normalStyle);
|
|
||||||
|
|
||||||
text.Span("Ten dokument został wygenerowany na podstawie książki w formacie TXT opublikowanej w serwisie ");
|
|
||||||
text.ExternalLocation("wolnelektury.pl", "https://wolnelektury.pl/", normalStyle.Color(Colors.Blue.Medium).Underline());
|
|
||||||
text.Span(". Dziękuję za wspieranie polskiego czytelnictwa!");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void SectionTitle(StackDescriptor stack, string text)
|
|
||||||
{
|
|
||||||
stack.Item().Location(text).Text(text, subtitleStyle);
|
|
||||||
stack.Item().PaddingTop(10).PaddingBottom(50).BorderBottom(1).BorderColor(Colors.Grey.Lighten2).ExtendHorizontal();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Footer(IContainer container)
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.AlignCenter()
|
|
||||||
.Text(text =>
|
|
||||||
{
|
|
||||||
text.CurrentPageNumber();
|
|
||||||
text.Span(" / ");
|
|
||||||
text.TotalPages();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,271 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Examples.Engine;
|
|
||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace QuestPDF.Examples
|
|
||||||
{
|
|
||||||
public class TextExamples
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void SimpleTextBlock()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(500, 300)
|
|
||||||
|
|
||||||
.ProduceImages()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(5)
|
|
||||||
.Box()
|
|
||||||
.Border(1)
|
|
||||||
.Padding(10)
|
|
||||||
.Text(text =>
|
|
||||||
{
|
|
||||||
text.DefaultTextStyle(TextStyle.Default.Size(20));
|
|
||||||
text.Span("This is a normal text, followed by an ");
|
|
||||||
text.Span("underlined red text.", TextStyle.Default.Size(20).Color(Colors.Red.Medium).Underline());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ParagraphSpacing()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(500, 300)
|
|
||||||
.ProduceImages()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(5)
|
|
||||||
.Box()
|
|
||||||
.Border(1)
|
|
||||||
.Padding(10)
|
|
||||||
.Text(text =>
|
|
||||||
{
|
|
||||||
text.ParagraphSpacing(10);
|
|
||||||
|
|
||||||
foreach (var i in Enumerable.Range(1, 3))
|
|
||||||
{
|
|
||||||
text.Span($"Paragraph {i}: ", TextStyle.Default.SemiBold());
|
|
||||||
text.Line(Placeholders.Paragraph());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void CustomElement()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(500, 200)
|
|
||||||
.ProduceImages()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(5)
|
|
||||||
.Box()
|
|
||||||
.Border(1)
|
|
||||||
.Padding(10)
|
|
||||||
.Text(text =>
|
|
||||||
{
|
|
||||||
text.DefaultTextStyle(TextStyle.Default.Size(20));
|
|
||||||
text.Span("This is a random image aligned to the baseline: ");
|
|
||||||
|
|
||||||
text.Element()
|
|
||||||
.PaddingBottom(-6)
|
|
||||||
.Height(24)
|
|
||||||
.Width(48)
|
|
||||||
.Image(Placeholders.Image);
|
|
||||||
|
|
||||||
text.Span(".");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TextElements()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(PageSizes.A4)
|
|
||||||
.ProducePdf()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(20)
|
|
||||||
.Padding(10)
|
|
||||||
.Box()
|
|
||||||
.Border(1)
|
|
||||||
.Padding(5)
|
|
||||||
.Padding(10)
|
|
||||||
.Text(text =>
|
|
||||||
{
|
|
||||||
text.DefaultTextStyle(TextStyle.Default);
|
|
||||||
text.AlignLeft();
|
|
||||||
text.ParagraphSpacing(10);
|
|
||||||
|
|
||||||
text.Line(Placeholders.LoremIpsum());
|
|
||||||
|
|
||||||
text.Span($"This is target text that should show up. {DateTime.UtcNow:T} > This is a short sentence that will be wrapped into second line hopefully, right? <", TextStyle.Default.Underline());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TextStack()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(PageSizes.A4)
|
|
||||||
.ProducePdf()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(20)
|
|
||||||
.Padding(10)
|
|
||||||
.Box()
|
|
||||||
.Border(1)
|
|
||||||
.Padding(5)
|
|
||||||
.Padding(10)
|
|
||||||
.Text(text =>
|
|
||||||
{
|
|
||||||
text.DefaultTextStyle(TextStyle.Default);
|
|
||||||
text.AlignLeft();
|
|
||||||
text.ParagraphSpacing(10);
|
|
||||||
|
|
||||||
foreach (var i in Enumerable.Range(1, 100))
|
|
||||||
text.Line($"{i}: {Placeholders.Paragraph()}");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SpaceIssue()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(PageSizes.A4)
|
|
||||||
.ProducePdf()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(20)
|
|
||||||
.Padding(10)
|
|
||||||
.Box()
|
|
||||||
.Border(1)
|
|
||||||
.Padding(5)
|
|
||||||
.Padding(10)
|
|
||||||
.Text(text =>
|
|
||||||
{
|
|
||||||
text.DefaultTextStyle(TextStyle.Default);
|
|
||||||
text.AlignLeft();
|
|
||||||
text.ParagraphSpacing(10);
|
|
||||||
|
|
||||||
text.Span(Placeholders.LoremIpsum());
|
|
||||||
|
|
||||||
text.EmptyLine();
|
|
||||||
|
|
||||||
text.Span("This text is a normal text, ");
|
|
||||||
text.Span("this is a bold text, ", TextStyle.Default.Bold());
|
|
||||||
text.Span("this is a red and underlined text, ", TextStyle.Default.Color(Colors.Red.Medium).Underline());
|
|
||||||
text.Span("and this is slightly bigger text.", TextStyle.Default.Size(16));
|
|
||||||
|
|
||||||
text.EmptyLine();
|
|
||||||
|
|
||||||
text.Span("The new text element also supports injecting custom content between words: ");
|
|
||||||
text.Element().PaddingBottom(-10).Height(16).Width(32).Image(Placeholders.Image);
|
|
||||||
text.Span(".");
|
|
||||||
|
|
||||||
text.EmptyLine();
|
|
||||||
|
|
||||||
text.Span("This is page number ");
|
|
||||||
text.CurrentPageNumber();
|
|
||||||
text.Span(" out of ");
|
|
||||||
text.TotalPages();
|
|
||||||
|
|
||||||
text.EmptyLine();
|
|
||||||
|
|
||||||
text.ExternalLocation("Please visit QuestPDF website", "https://www.questpdf.com");
|
|
||||||
|
|
||||||
text.EmptyLine();
|
|
||||||
|
|
||||||
text.Span(Placeholders.Paragraphs());
|
|
||||||
|
|
||||||
|
|
||||||
text.EmptyLine();
|
|
||||||
|
|
||||||
text.Span(Placeholders.Paragraphs(), TextStyle.Default.Italic());
|
|
||||||
|
|
||||||
text.Line("This is target text that does not show up. " + Placeholders.Paragraph());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void HugeList()
|
|
||||||
{
|
|
||||||
RenderingTest
|
|
||||||
.Create()
|
|
||||||
.PageSize(PageSizes.A4)
|
|
||||||
.ProducePdf()
|
|
||||||
.ShowResults()
|
|
||||||
.Render(container =>
|
|
||||||
{
|
|
||||||
container
|
|
||||||
.Padding(20)
|
|
||||||
.Padding(10)
|
|
||||||
.Box()
|
|
||||||
.Border(1)
|
|
||||||
.Padding(5)
|
|
||||||
.Padding(10)
|
|
||||||
.Text(text =>
|
|
||||||
{
|
|
||||||
text.DefaultTextStyle(TextStyle.Default);
|
|
||||||
text.AlignLeft();
|
|
||||||
text.ParagraphSpacing(10);
|
|
||||||
|
|
||||||
text.Span("This text is a normal text, ");
|
|
||||||
text.Span("this is a bold text, ", TextStyle.Default.Bold());
|
|
||||||
text.Span("this is a red and underlined text, ", TextStyle.Default.Color(Colors.Red.Medium).Underline());
|
|
||||||
text.Span("and this is slightly bigger text.", TextStyle.Default.Size(16));
|
|
||||||
|
|
||||||
text.Span("The new text element also supports injecting custom content between words: ");
|
|
||||||
text.Element().PaddingBottom(-10).Height(16).Width(32).Image(Placeholders.Image);
|
|
||||||
text.Span(".");
|
|
||||||
|
|
||||||
text.EmptyLine();
|
|
||||||
|
|
||||||
foreach (var i in Enumerable.Range(1, 100))
|
|
||||||
{
|
|
||||||
text.Line($"{i}: {Placeholders.Paragraph()}");
|
|
||||||
|
|
||||||
text.ExternalLocation("Please visit QuestPDF website", "https://www.questpdf.com");
|
|
||||||
|
|
||||||
text.Span("This is page number ");
|
|
||||||
text.CurrentPageNumber();
|
|
||||||
text.Span(" out of ");
|
|
||||||
text.TotalPages();
|
|
||||||
|
|
||||||
text.EmptyLine();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 26 KiB |
@@ -2,11 +2,15 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using QuestPDF.Helpers;
|
using QuestPDF.Helpers;
|
||||||
|
using QuestPDF.ReportSample.Layouts;
|
||||||
|
|
||||||
namespace QuestPDF.ReportSample
|
namespace QuestPDF.ReportSample
|
||||||
{
|
{
|
||||||
public static class DataSource
|
public static class DataSource
|
||||||
{
|
{
|
||||||
|
public static int SectionCounter { get; set; }
|
||||||
|
public static int FieldCounter { get; set; }
|
||||||
|
|
||||||
public static ReportModel GetReport()
|
public static ReportModel GetReport()
|
||||||
{
|
{
|
||||||
return new ReportModel
|
return new ReportModel
|
||||||
@@ -14,9 +18,9 @@ namespace QuestPDF.ReportSample
|
|||||||
Title = "Sample Report Document",
|
Title = "Sample Report Document",
|
||||||
HeaderFields = HeaderFields(),
|
HeaderFields = HeaderFields(),
|
||||||
|
|
||||||
LogoData = Helpers.GetImage("Logo.png"),
|
LogoData = Helpers.GetImage("logo.png"),
|
||||||
Sections = Enumerable.Range(0, 40).Select(x => GenerateSection()).ToList(),
|
Sections = Enumerable.Range(0, 8).Select(x => GenerateSection()).ToList(),
|
||||||
Photos = Enumerable.Range(0, 25).Select(x => GetReportPhotos()).ToList()
|
Photos = Enumerable.Range(0, 8).Select(x => GetReportPhotos()).ToList()
|
||||||
};
|
};
|
||||||
|
|
||||||
List<ReportHeaderField> HeaderFields()
|
List<ReportHeaderField> HeaderFields()
|
||||||
@@ -37,11 +41,6 @@ namespace QuestPDF.ReportSample
|
|||||||
{
|
{
|
||||||
Label = "Date",
|
Label = "Date",
|
||||||
Value = DateTime.Now.ToString("g")
|
Value = DateTime.Now.ToString("g")
|
||||||
},
|
|
||||||
new ReportHeaderField()
|
|
||||||
{
|
|
||||||
Label = "Status",
|
|
||||||
Value = "Completed, found 2 issues"
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -49,12 +48,12 @@ namespace QuestPDF.ReportSample
|
|||||||
ReportSection GenerateSection()
|
ReportSection GenerateSection()
|
||||||
{
|
{
|
||||||
var sectionLength = Helpers.Random.NextDouble() > 0.75
|
var sectionLength = Helpers.Random.NextDouble() > 0.75
|
||||||
? Helpers.Random.Next(20, 40)
|
? Helpers.Random.Next(10, 20)
|
||||||
: Helpers.Random.Next(5, 10);
|
: Helpers.Random.Next(3, 11);
|
||||||
|
|
||||||
return new ReportSection
|
return new ReportSection
|
||||||
{
|
{
|
||||||
Title = Placeholders.Label(),
|
Title = TextPlaceholder.Label(),
|
||||||
Parts = Enumerable.Range(0, sectionLength).Select(x => GetRandomElement()).ToList()
|
Parts = Enumerable.Range(0, sectionLength).Select(x => GetRandomElement()).ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -63,10 +62,10 @@ namespace QuestPDF.ReportSample
|
|||||||
{
|
{
|
||||||
var random = Helpers.Random.NextDouble();
|
var random = Helpers.Random.NextDouble();
|
||||||
|
|
||||||
if (random < 0.9f)
|
if (random < 0.8f)
|
||||||
return GetTextElement();
|
return GetTextElement();
|
||||||
|
|
||||||
if (random < 0.95f)
|
if (random < 0.9f)
|
||||||
return GetMapElement();
|
return GetMapElement();
|
||||||
|
|
||||||
return GetPhotosElement();
|
return GetPhotosElement();
|
||||||
@@ -76,16 +75,19 @@ namespace QuestPDF.ReportSample
|
|||||||
{
|
{
|
||||||
return new ReportSectionText
|
return new ReportSectionText
|
||||||
{
|
{
|
||||||
Label = Placeholders.Label(),
|
Label = TextPlaceholder.Label(),
|
||||||
Text = Placeholders.Paragraph()
|
Text = TextPlaceholder.Paragraph()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportSectionMap GetMapElement()
|
ReportSectionMap GetMapElement()
|
||||||
{
|
{
|
||||||
|
var rnd = Helpers.Random.Next(0, 64);
|
||||||
|
|
||||||
return new ReportSectionMap
|
return new ReportSectionMap
|
||||||
{
|
{
|
||||||
Label = "Location",
|
Label = "Location",
|
||||||
|
ImageSource = x => Helpers.GetDocumentMap($"{rnd}.jpg"),
|
||||||
Location = Helpers.RandomLocation()
|
Location = Helpers.RandomLocation()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -95,17 +97,29 @@ namespace QuestPDF.ReportSample
|
|||||||
return new ReportSectionPhotos
|
return new ReportSectionPhotos
|
||||||
{
|
{
|
||||||
Label = "Photos",
|
Label = "Photos",
|
||||||
PhotoCount = Helpers.Random.Next(1, 15)
|
Photos = Enumerable
|
||||||
|
.Range(0, Helpers.Random.Next(1, 10))
|
||||||
|
.Select(x => Helpers.Random.Next(0, 128))
|
||||||
|
.Select(x => Helpers.GetPhoto($"{x}.jpg"))
|
||||||
|
.ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportPhoto GetReportPhotos()
|
ReportPhoto GetReportPhotos()
|
||||||
{
|
{
|
||||||
|
var photoId = Helpers.Random.Next(0, 128);
|
||||||
|
var mapId = Helpers.Random.Next(0, 64);
|
||||||
|
|
||||||
return new ReportPhoto()
|
return new ReportPhoto()
|
||||||
{
|
{
|
||||||
Comments = Placeholders.Sentence(),
|
PhotoData = Helpers.GetPhoto($"{photoId}.jpg"),
|
||||||
|
|
||||||
|
Comments = TextPlaceholder.Paragraph(),
|
||||||
Date = DateTime.Now - TimeSpan.FromDays(Helpers.Random.NextDouble() * 100),
|
Date = DateTime.Now - TimeSpan.FromDays(Helpers.Random.NextDouble() * 100),
|
||||||
Location = Helpers.RandomLocation()
|
Location = Helpers.RandomLocation(),
|
||||||
|
|
||||||
|
MapContextSource = x => Helpers.GetContextMap($"{mapId}.jpg"),
|
||||||
|
MapDetailsSource = x => Helpers.GetDetailsMap($"{mapId}.jpg")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using QuestPDF.ReportSample.Layouts;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace QuestPDF.ReportSample
|
namespace QuestPDF.ReportSample
|
||||||
{
|
{
|
||||||
public static class Helpers
|
public static class Helpers
|
||||||
{
|
{
|
||||||
public static Random Random { get; } = new Random(1);
|
public static Random Random { get; } = new Random();
|
||||||
|
|
||||||
public static string GetTestItem(string path) => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", path);
|
public static string GetTestItem(string path) => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", path);
|
||||||
|
|
||||||
|
public static byte[] GetDocumentMap(string name) => GetImage(Path.Combine("Maps", "Document", name));
|
||||||
|
public static byte[] GetDetailsMap(string name) => GetImage(Path.Combine("Maps", "Details", name));
|
||||||
|
public static byte[] GetContextMap(string name) => GetImage(Path.Combine("Maps", "Context", name));
|
||||||
|
|
||||||
|
public static byte[] GetPhoto(string name) => GetImage(Path.Combine("Photos", name));
|
||||||
|
|
||||||
public static byte[] GetImage(string name)
|
public static byte[] GetImage(string name)
|
||||||
{
|
{
|
||||||
var photoPath = GetTestItem(name);
|
var photoPath = GetTestItem(name);
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
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");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
using QuestPDF.Infrastructure;
|
||||||
|
|
||||||
namespace QuestPDF.ReportSample.Layouts
|
namespace QuestPDF.ReportSample.Layouts
|
||||||
{
|
{
|
||||||
public static class Helpers
|
public static class Helpers
|
||||||
{
|
{
|
||||||
static IContainer Cell(this IContainer container, bool background)
|
static IContainer Cell(this IContainer container, string color)
|
||||||
{
|
{
|
||||||
return container
|
return container
|
||||||
.Border(0.5f)
|
.Border(0.5f)
|
||||||
.BorderColor(Colors.Grey.Lighten1)
|
.Background(color)
|
||||||
.Background(background ? Colors.Grey.Lighten4 : Colors.White)
|
|
||||||
.Padding(5);
|
.Padding(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IContainer ValueCell(this IContainer container)
|
public static IContainer LightCell(this IContainer container)
|
||||||
{
|
{
|
||||||
return container.Cell(false);
|
return container.Cell("#0000");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IContainer LabelCell(this IContainer container)
|
public static IContainer DarkCell(this IContainer container)
|
||||||
{
|
{
|
||||||
return container.Cell(true);
|
return container.Cell("#1000");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Format(this Location location)
|
public static string Format(this Location location)
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
using QuestPDF.Fluent;
|
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
|
|
||||||
namespace QuestPDF.ReportSample.Layouts
|
|
||||||
{
|
|
||||||
public class ImagePlaceholder : IComponent
|
|
||||||
{
|
|
||||||
public static bool Solid { get; set; } = false;
|
|
||||||
|
|
||||||
public void Compose(IContainer container)
|
|
||||||
{
|
|
||||||
if (Solid)
|
|
||||||
container.Background(Placeholders.Color());
|
|
||||||
|
|
||||||
else
|
|
||||||
container.Image(Placeholders.Image);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using QuestPDF.Fluent;
|
||||||
|
using QuestPDF.Infrastructure;
|
||||||
|
|
||||||
|
namespace QuestPDF.ReportSample.Layouts
|
||||||
|
{
|
||||||
|
public class ImageTemplate : IComponent
|
||||||
|
{
|
||||||
|
private Func<Size, byte[]> Source { get; }
|
||||||
|
private float AspectRatio { get; }
|
||||||
|
|
||||||
|
public ImageTemplate(byte[] source, float aspectRatio = 1.333333f) : this(_ => source, aspectRatio)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageTemplate(Func<Size, byte[]> source, float aspectRatio = 1.333333f)
|
||||||
|
{
|
||||||
|
Source = source;
|
||||||
|
AspectRatio = aspectRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Compose(IContainer container)
|
||||||
|
{
|
||||||
|
container
|
||||||
|
.AspectRatio(AspectRatio)
|
||||||
|
.Background("#EEEEEE")
|
||||||
|
.Image(Source(Size.Zero));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
using QuestPDF.Infrastructure;
|
||||||
|
|
||||||
namespace QuestPDF.ReportSample.Layouts
|
namespace QuestPDF.ReportSample.Layouts
|
||||||
@@ -16,45 +15,47 @@ namespace QuestPDF.ReportSample.Layouts
|
|||||||
public void Compose(IContainer container)
|
public void Compose(IContainer container)
|
||||||
{
|
{
|
||||||
container
|
container
|
||||||
.ShowEntire()
|
|
||||||
.Stack(stack =>
|
.Stack(stack =>
|
||||||
{
|
{
|
||||||
stack.Spacing(5);
|
stack.Element(PhotoWithMaps);
|
||||||
stack.Item().Element(PhotoWithMaps);
|
stack.Element(PhotoDetails);
|
||||||
stack.Item().Element(PhotoDetails);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhotoWithMaps(IContainer container)
|
void PhotoWithMaps(IContainer container)
|
||||||
{
|
{
|
||||||
container
|
container
|
||||||
|
.Padding(-3)
|
||||||
|
.PaddingBottom(3)
|
||||||
.Row(row =>
|
.Row(row =>
|
||||||
{
|
{
|
||||||
row.RelativeColumn(2).AspectRatio(4 / 3f).Component<ImagePlaceholder>();
|
row.RelativeColumn(2).Padding(3).Component(new ImageTemplate(Model.PhotoData));
|
||||||
|
|
||||||
row.RelativeColumn().PaddingLeft(5).Stack(stack =>
|
row.RelativeColumn().Stack(stack =>
|
||||||
{
|
{
|
||||||
stack.Spacing(7f);
|
stack.Element().Padding(3).Component(new ImageTemplate(Model.MapDetailsSource));
|
||||||
|
stack.Element().Padding(3).Component(new ImageTemplate(Model.MapContextSource));
|
||||||
stack.Item().AspectRatio(4 / 3f).Component<ImagePlaceholder>();
|
|
||||||
stack.Item().AspectRatio(4 / 3f).Component<ImagePlaceholder>();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhotoDetails(IContainer container)
|
void PhotoDetails(IContainer container)
|
||||||
{
|
{
|
||||||
container.Border(0.75f).BorderColor(Colors.Grey.Medium).Grid(grid =>
|
container.Stack(stack =>
|
||||||
{
|
{
|
||||||
grid.Columns(6);
|
stack.Element().Row(row =>
|
||||||
|
{
|
||||||
|
row.RelativeColumn().DarkCell().Text("Date", Typography.Normal);
|
||||||
|
row.RelativeColumn(2).LightCell().Text(Model.Date?.ToString("g") ?? string.Empty, Typography.Normal);
|
||||||
|
row.RelativeColumn().DarkCell().Text("Location", Typography.Normal);
|
||||||
|
row.RelativeColumn(2).LightCell().Text(Model.Location.Format(), Typography.Normal);
|
||||||
|
});
|
||||||
|
|
||||||
grid.Item().LabelCell().Text("Date");
|
stack.Element().Row(row =>
|
||||||
grid.Item(2).ValueCell().Text(Model.Date?.ToString("g") ?? string.Empty);
|
{
|
||||||
grid.Item().LabelCell().Text("Location");
|
row.RelativeColumn().DarkCell().Text("Comments", Typography.Normal);
|
||||||
grid.Item(2).ValueCell().Text(Model.Location.Format());
|
row.RelativeColumn(5).LightCell().Text(Model.Comments, Typography.Normal);
|
||||||
|
});
|
||||||
grid.Item().LabelCell().Text("Comments");
|
|
||||||
grid.Item(5).ValueCell().Text(Model.Comments);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
using QuestPDF.Helpers;
|
|
||||||
using QuestPDF.Infrastructure;
|
using QuestPDF.Infrastructure;
|
||||||
|
|
||||||
namespace QuestPDF.ReportSample.Layouts
|
namespace QuestPDF.ReportSample.Layouts
|
||||||
@@ -17,25 +17,25 @@ namespace QuestPDF.ReportSample.Layouts
|
|||||||
public void Compose(IContainer container)
|
public void Compose(IContainer container)
|
||||||
{
|
{
|
||||||
container
|
container
|
||||||
.EnsureSpace()
|
.MinHeight(100)
|
||||||
.Decoration(decoration =>
|
.Section(section =>
|
||||||
{
|
{
|
||||||
decoration
|
section
|
||||||
.Header()
|
.Header()
|
||||||
.PaddingBottom(5)
|
.PaddingBottom(5)
|
||||||
.Text(Model.Title, Typography.Headline);
|
.Text(Model.Title, Typography.Headline);
|
||||||
|
|
||||||
decoration.Content().Border(0.75f).BorderColor(Colors.Grey.Medium).Stack(stack =>
|
section.Content().PageableStack(stack =>
|
||||||
{
|
{
|
||||||
foreach (var part in Model.Parts)
|
foreach (var part in Model.Parts)
|
||||||
{
|
{
|
||||||
stack.Item().EnsureSpace(25).Row(row =>
|
stack.Element().Row(row =>
|
||||||
{
|
{
|
||||||
row.ConstantColumn(150).LabelCell().Text(part.Label);
|
row.ConstantColumn(150).DarkCell().Text(part.Label, Typography.Normal);
|
||||||
var frame = row.RelativeColumn().ValueCell();
|
var frame = row.RelativeColumn().LightCell();
|
||||||
|
|
||||||
if (part is ReportSectionText text)
|
if (part is ReportSectionText text)
|
||||||
frame.ShowEntire().Text(text.Text);
|
frame.Text(text.Text, Typography.Normal);
|
||||||
|
|
||||||
if (part is ReportSectionMap map)
|
if (part is ReportSectionMap map)
|
||||||
frame.Element(x => MapElement(x, map));
|
frame.Element(x => MapElement(x, map));
|
||||||
@@ -50,38 +50,44 @@ namespace QuestPDF.ReportSample.Layouts
|
|||||||
|
|
||||||
void MapElement(IContainer container, ReportSectionMap model)
|
void MapElement(IContainer container, ReportSectionMap model)
|
||||||
{
|
{
|
||||||
if (model.Location == null)
|
if (model.ImageSource == null || model.Location == null)
|
||||||
{
|
{
|
||||||
container.Text("No location provided");
|
container.Text("No location provided", Typography.Normal);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.ShowEntire().Stack(stack =>
|
container.PageableStack(stack =>
|
||||||
{
|
{
|
||||||
stack.Spacing(5);
|
stack.Spacing(5);
|
||||||
|
|
||||||
stack.Item().MaxWidth(250).AspectRatio(4 / 3f).Component<ImagePlaceholder>();
|
stack.Element().Component(new ImageTemplate(model.ImageSource));
|
||||||
stack.Item().Text(model.Location.Format());
|
stack.Element().Text(model.Location.Format(), Typography.Normal);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhotosElement(IContainer container, ReportSectionPhotos model)
|
void PhotosElement(IContainer container, ReportSectionPhotos model)
|
||||||
{
|
{
|
||||||
if (model.PhotoCount == 0)
|
if (model.Photos.Count == 0)
|
||||||
{
|
{
|
||||||
container.Text("No photos", Typography.Normal);
|
container.Text("No photos", Typography.Normal);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.DebugArea("Photos").Grid(grid =>
|
var rowCount = (int) Math.Ceiling(model.Photos.Count / 3f);
|
||||||
{
|
|
||||||
grid.Spacing(5);
|
|
||||||
grid.Columns(3);
|
|
||||||
|
|
||||||
Enumerable
|
container.Debug().Padding(-2).PageableStack(stack =>
|
||||||
.Range(0, model.PhotoCount)
|
{
|
||||||
.ToList()
|
foreach (var rowId in Enumerable.Range(0, rowCount))
|
||||||
.ForEach(x => grid.Item().AspectRatio(4 / 3f).Component<ImagePlaceholder>());
|
{
|
||||||
|
stack.Element().Row(row =>
|
||||||
|
{
|
||||||
|
foreach (var id in Enumerable.Range(0, 3))
|
||||||
|
{
|
||||||
|
var data = model.Photos.ElementAtOrDefault(rowId + id);
|
||||||
|
row.RelativeColumn().Padding(2).Component(new ImageTemplate(data));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,83 +18,79 @@ namespace QuestPDF.ReportSample.Layouts
|
|||||||
{
|
{
|
||||||
return new DocumentMetadata()
|
return new DocumentMetadata()
|
||||||
{
|
{
|
||||||
Title = Model.Title
|
Title = Model.Title,
|
||||||
|
Size = PageSizes.A4
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Compose(IDocumentContainer container)
|
public void Compose(IContainer container)
|
||||||
{
|
{
|
||||||
container
|
container
|
||||||
|
.PaddingVertical(40)
|
||||||
|
.PaddingHorizontal(50)
|
||||||
|
|
||||||
.Page(page =>
|
.Page(page =>
|
||||||
{
|
{
|
||||||
page.DefaultTextStyle(Typography.Normal);
|
page.Header(ComposeHeader);
|
||||||
|
page.Content(ComposeContent);
|
||||||
page.MarginVertical(40);
|
page.Footer().AlignCenter().PageNumber("Page {number}");
|
||||||
page.MarginHorizontal(50);
|
|
||||||
|
|
||||||
page.Size(PageSizes.A4);
|
|
||||||
|
|
||||||
page.Header().Element(ComposeHeader);
|
|
||||||
page.Content().Element(ComposeContent);
|
|
||||||
|
|
||||||
page.Footer().AlignCenter().Text(text =>
|
|
||||||
{
|
|
||||||
text.CurrentPageNumber();
|
|
||||||
text.Span(" / ");
|
|
||||||
text.TotalPages();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ComposeHeader(IContainer container)
|
private void ComposeHeader(IContainer container)
|
||||||
{
|
{
|
||||||
container.Stack(stack =>
|
container.Row(row =>
|
||||||
{
|
{
|
||||||
stack.Item().Row(row =>
|
row.RelativeColumn().MaxWidth(300).Stack(stack =>
|
||||||
{
|
{
|
||||||
row.Spacing(50);
|
stack.Spacing(5);
|
||||||
|
|
||||||
row.RelativeColumn().PaddingTop(-10).Text(Model.Title, Typography.Title);
|
stack
|
||||||
row.ConstantColumn(90).ExternalLink("https://www.questpdf.com").MaxHeight(30).Component<ImagePlaceholder>();
|
.Element()
|
||||||
});
|
.PaddingBottom(5)
|
||||||
|
.Text(Model.Title, Typography.Title);
|
||||||
|
|
||||||
stack.Item().ShowOnce().PaddingVertical(15).Border(1f).BorderColor(Colors.Grey.Lighten1).ExtendHorizontal();
|
stack.Element().ShowOnce().Stack(table =>
|
||||||
|
|
||||||
stack.Item().ShowOnce().Grid(grid =>
|
|
||||||
{
|
|
||||||
grid.Columns(2);
|
|
||||||
grid.Spacing(5);
|
|
||||||
|
|
||||||
foreach (var field in Model.HeaderFields)
|
|
||||||
{
|
{
|
||||||
grid.Item().Text(text =>
|
table.Spacing(5);
|
||||||
|
|
||||||
|
foreach (var field in Model.HeaderFields)
|
||||||
{
|
{
|
||||||
text.Span($"{field.Label}: ", TextStyle.Default.SemiBold());
|
table.Element().Row(row =>
|
||||||
text.Span(field.Value);
|
{
|
||||||
});
|
row.ConstantColumn(50)
|
||||||
}
|
.AlignLeft()
|
||||||
|
.Text($"{field.Label}:", Typography.Normal);
|
||||||
|
|
||||||
|
row.RelativeColumn()
|
||||||
|
.PaddingLeft(10)
|
||||||
|
.Text(field.Value, Typography.Normal);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
row.ConstantColumn(150).ExternalLink("https://www.questpdf.com").Image(Model.LogoData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComposeContent(IContainer container)
|
void ComposeContent(IContainer container)
|
||||||
{
|
{
|
||||||
container.PaddingVertical(20).Stack(stack =>
|
container.PaddingVertical(20).PageableStack(stack =>
|
||||||
{
|
{
|
||||||
stack.Spacing(20);
|
stack.Spacing(20);
|
||||||
|
|
||||||
stack.Item().Component(new TableOfContentsTemplate(Model.Sections));
|
stack.Element().Component(new TableOfContentsTemplate(Model.Sections));
|
||||||
|
|
||||||
stack.Item().PageBreak();
|
|
||||||
|
|
||||||
foreach (var section in Model.Sections)
|
foreach (var section in Model.Sections)
|
||||||
stack.Item().Location(section.Title).Component(new SectionTemplate(section));
|
stack.Element().Location(section.Title).Component(new SectionTemplate(section));
|
||||||
|
|
||||||
stack.Item().PageBreak();
|
stack.Element().PageBreak();
|
||||||
stack.Item().Location("Photos");
|
stack.Element().Location("Photos");
|
||||||
|
|
||||||
foreach (var photo in Model.Photos)
|
foreach (var photo in Model.Photos)
|
||||||
stack.Item().Component(new PhotoTemplate(photo));
|
stack.Element().Component(new PhotoTemplate(photo));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
using QuestPDF.Infrastructure;
|
using QuestPDF.Infrastructure;
|
||||||
|
|
||||||
@@ -16,21 +18,21 @@ namespace QuestPDF.ReportSample.Layouts
|
|||||||
public void Compose(IContainer container)
|
public void Compose(IContainer container)
|
||||||
{
|
{
|
||||||
container
|
container
|
||||||
.Decoration(decoration =>
|
.Section(section =>
|
||||||
{
|
{
|
||||||
decoration
|
section
|
||||||
.Header()
|
.Header()
|
||||||
.PaddingBottom(5)
|
.PaddingBottom(5)
|
||||||
.Text("Table of contents", Typography.Headline);
|
.Text("Table of contents", Typography.Headline);
|
||||||
|
|
||||||
decoration.Content().Stack(stack =>
|
section.Content().PageableStack(stack =>
|
||||||
{
|
{
|
||||||
stack.Spacing(5);
|
stack.Spacing(5);
|
||||||
|
|
||||||
for (var i = 0; i < Sections.Count; i++)
|
for (var i = 0; i < Sections.Count; i++)
|
||||||
stack.Item().Element(c => DrawLink(c, i+1, Sections[i].Title));
|
stack.Element(c => DrawLink(c, i+1, Sections[i].Title));
|
||||||
|
|
||||||
stack.Item().Element(c => DrawLink(c, Sections.Count+1, "Photos"));
|
stack.Element(c => DrawLink(c, Sections.Count+1, "Photos"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -41,9 +43,8 @@ namespace QuestPDF.ReportSample.Layouts
|
|||||||
.InternalLink(locationName)
|
.InternalLink(locationName)
|
||||||
.Row(row =>
|
.Row(row =>
|
||||||
{
|
{
|
||||||
row.ConstantColumn(25).Text($"{number}.");
|
row.ConstantColumn(25).Text($"{number}.", Typography.Normal);
|
||||||
row.RelativeColumn().Text(locationName);
|
row.RelativeColumn().Text(locationName, Typography.Normal);
|
||||||
row.ConstantColumn(150).AlignRight().Text(text => text.PageNumberOfLocation(locationName));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,16 +44,22 @@ namespace QuestPDF.ReportSample
|
|||||||
|
|
||||||
public class ReportSectionMap : ReportSectionElement
|
public class ReportSectionMap : ReportSectionElement
|
||||||
{
|
{
|
||||||
|
public Func<Size, byte[]> ImageSource { get; set; }
|
||||||
public Location Location { get; set; }
|
public Location Location { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReportSectionPhotos : ReportSectionElement
|
public class ReportSectionPhotos : ReportSectionElement
|
||||||
{
|
{
|
||||||
public int PhotoCount { get; set; }
|
public List<byte[]> Photos { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReportPhoto
|
public class ReportPhoto
|
||||||
{
|
{
|
||||||
|
public byte[] PhotoData { get; set; }
|
||||||
|
|
||||||
|
public Func<Size, byte[]> MapDetailsSource { get; set; }
|
||||||
|
public Func<Size, byte[]> MapContextSource { get; set; }
|
||||||
|
|
||||||
public Location Location { get; set; }
|
public Location Location { get; set; }
|
||||||
|
|
||||||
public DateTime? Date { get; set; }
|
public DateTime? Date { get; set; }
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using BenchmarkDotNet.Attributes;
|
|
||||||
using BenchmarkDotNet.Configs;
|
|
||||||
using BenchmarkDotNet.Engines;
|
|
||||||
using BenchmarkDotNet.Running;
|
|
||||||
using Microsoft.VisualStudio.TestPlatform.TestHost;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using QuestPDF.Drawing;
|
|
||||||
using QuestPDF.Drawing.Proxy;
|
|
||||||
using QuestPDF.Elements;
|
|
||||||
using QuestPDF.Infrastructure;
|
|
||||||
using QuestPDF.ReportSample.Layouts;
|
|
||||||
|
|
||||||
namespace QuestPDF.ReportSample
|
|
||||||
{
|
|
||||||
[SimpleJob(RunStrategy.Monitoring, launchCount: 0, warmupCount: 1, targetCount: 256)]
|
|
||||||
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
|
|
||||||
public class PerformanceTests
|
|
||||||
{
|
|
||||||
private PageContext PageContext { get; set; }
|
|
||||||
private DocumentMetadata Metadata { get; set; }
|
|
||||||
private Container Content { get; set; }
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Run()
|
|
||||||
{
|
|
||||||
ImagePlaceholder.Solid = true;
|
|
||||||
|
|
||||||
var configuration = ManualConfig
|
|
||||||
.Create(DefaultConfig.Instance)
|
|
||||||
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
|
|
||||||
|
|
||||||
BenchmarkRunner.Run<PerformanceTests>(configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
[IterationSetup]
|
|
||||||
public void GenerateReportData()
|
|
||||||
{
|
|
||||||
ImagePlaceholder.Solid = true;
|
|
||||||
|
|
||||||
var model = DataSource.GetReport();
|
|
||||||
var report = new StandardReport(model);
|
|
||||||
Metadata = report.GetMetadata();
|
|
||||||
|
|
||||||
var documentContainer = new DocumentContainer();
|
|
||||||
report.Compose(documentContainer);
|
|
||||||
Content = documentContainer.Compose();
|
|
||||||
|
|
||||||
PageContext = new PageContext();
|
|
||||||
DocumentGenerator.RenderPass(PageContext, new FreeCanvas(), Content, Metadata, null);
|
|
||||||
|
|
||||||
var sw = new Stopwatch();
|
|
||||||
sw.Start();
|
|
||||||
|
|
||||||
Content.HandleVisitor(x =>
|
|
||||||
{
|
|
||||||
if (x is ICacheable)
|
|
||||||
x.CreateProxy(y => new CacheProxy(y));
|
|
||||||
});
|
|
||||||
|
|
||||||
sw.Stop();
|
|
||||||
Console.WriteLine($"Creating cache took: {sw.ElapsedMilliseconds}");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void GenerationTest()
|
|
||||||
{
|
|
||||||
DocumentGenerator.RenderPass(PageContext, new FreeCanvas(), Content, Metadata, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,14 +8,19 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
|
<PackageReference Include="DeepCloner" Version="0.10.2" />
|
||||||
<PackageReference Include="nunit" Version="3.13.2" />
|
<PackageReference Include="nunit" Version="3.12.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||||
<PackageReference Include="SkiaSharp" Version="2.80.3" />
|
<PackageReference Include="SkiaSharp" Version="2.80.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Folder Include="Resources" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Resources\Photos\readme.txt" />
|
||||||
<Content Include="Resources\**\**">
|
<Content Include="Resources\**\**">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
@@ -24,8 +29,4 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\QuestPDF\QuestPDF.csproj" />
|
<ProjectReference Include="..\QuestPDF\QuestPDF.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<EmbeddedResource Include="Resources\Logo.png" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 35 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 35 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 34 KiB |