|
@@ -1,17 +1,21 @@
|
|
|
using System;
|
|
using System;
|
|
|
|
|
+using System.ComponentModel;
|
|
|
|
|
+using System.Diagnostics;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using NUnit.Framework;
|
|
using NUnit.Framework;
|
|
|
|
|
+using QuestPDF.Drawing;
|
|
|
using QuestPDF.Examples.Engine;
|
|
using QuestPDF.Examples.Engine;
|
|
|
using QuestPDF.Fluent;
|
|
using QuestPDF.Fluent;
|
|
|
using QuestPDF.Helpers;
|
|
using QuestPDF.Helpers;
|
|
|
using QuestPDF.Infrastructure;
|
|
using QuestPDF.Infrastructure;
|
|
|
|
|
+using IContainer = QuestPDF.Infrastructure.IContainer;
|
|
|
|
|
|
|
|
namespace QuestPDF.Examples
|
|
namespace QuestPDF.Examples
|
|
|
{
|
|
{
|
|
|
public class TableExamples
|
|
public class TableExamples
|
|
|
{
|
|
{
|
|
|
public static Random Random { get; } = new Random();
|
|
public static Random Random { get; } = new Random();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
[Test]
|
|
[Test]
|
|
|
public void Example()
|
|
public void Example()
|
|
|
{
|
|
{
|
|
@@ -51,86 +55,148 @@ namespace QuestPDF.Examples
|
|
|
table.Cell().RowSpan(2).Element(CreateBox("K"));
|
|
table.Cell().RowSpan(2).Element(CreateBox("K"));
|
|
|
table.Cell().ColumnSpan(2).Element(CreateBox("L"));
|
|
table.Cell().ColumnSpan(2).Element(CreateBox("L"));
|
|
|
table.Cell().Element(CreateBox("M"));
|
|
table.Cell().Element(CreateBox("M"));
|
|
|
-
|
|
|
|
|
- // table.Cell().Row(1).Column(1).ColumnSpan(2).Element(CreateBox("A"));
|
|
|
|
|
- // table.Cell().Row(1).Column(3).Element(CreateBox("B"));
|
|
|
|
|
- // table.Cell().Row(1).Column(4).Element(CreateBox("C"));
|
|
|
|
|
- //
|
|
|
|
|
- // table.Cell().Row(2).Column(1).Element(CreateBox("D"));
|
|
|
|
|
- // table.Cell().Row(2).RowSpan(2).Column(2).Element(CreateBox("E"));
|
|
|
|
|
- // table.Cell().Row(2).RowSpan(3).Column(3).ColumnSpan(2).Element(CreateBox("F"));
|
|
|
|
|
- //
|
|
|
|
|
- // table.Cell().Row(3).RowSpan(2).Column(1).Element(CreateBox("G"));
|
|
|
|
|
- // table.Cell().Row(4).RowSpan(2).Column(2).Element(CreateBox("H"));
|
|
|
|
|
- // table.Cell().Row(5).Column(3).Element(CreateBox("I"));
|
|
|
|
|
- // table.Cell().Row(5).Column(4).Element(CreateBox("J"));
|
|
|
|
|
- // table.Cell().Row(5).RowSpan(2).Column(1).Element(CreateBox("K"));
|
|
|
|
|
- // table.Cell().Row(6).Column(2).ColumnSpan(2).Element(CreateBox("L"));
|
|
|
|
|
- // table.Cell().Row(6).Column(4).Element(CreateBox("M"));
|
|
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
[Test]
|
|
|
- public void PerformanceTest()
|
|
|
|
|
|
|
+ public void TreeTable()
|
|
|
{
|
|
{
|
|
|
RenderingTest
|
|
RenderingTest
|
|
|
.Create()
|
|
.Create()
|
|
|
.ProducePdf()
|
|
.ProducePdf()
|
|
|
- .PageSize(1002, 2002)
|
|
|
|
|
- .MaxPages(1000)
|
|
|
|
|
- .EnableCaching()
|
|
|
|
|
- .EnableDebugging(false)
|
|
|
|
|
|
|
+ .PageSize(PageSizes.A4)
|
|
|
.ShowResults()
|
|
.ShowResults()
|
|
|
.Render(container =>
|
|
.Render(container =>
|
|
|
{
|
|
{
|
|
|
container
|
|
container
|
|
|
- .Padding(1)
|
|
|
|
|
|
|
+ .Padding(25)
|
|
|
|
|
+ .Box()
|
|
|
|
|
+ .Border(2)
|
|
|
.Table(table =>
|
|
.Table(table =>
|
|
|
{
|
|
{
|
|
|
table.ColumnsDefinition(columns =>
|
|
table.ColumnsDefinition(columns =>
|
|
|
{
|
|
{
|
|
|
- foreach (var size in Enumerable.Range(0, 10))
|
|
|
|
|
- columns.ConstantColumn(100);
|
|
|
|
|
|
|
+ columns.RelativeColumn(100);
|
|
|
|
|
+ columns.RelativeColumn(100);
|
|
|
|
|
+ columns.RelativeColumn(100);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- foreach (var i in Enumerable.Range(1, 10_000))
|
|
|
|
|
- {
|
|
|
|
|
- table
|
|
|
|
|
- .Cell()
|
|
|
|
|
- .RowSpan((uint)Random.Next(1, 5))
|
|
|
|
|
- .ColumnSpan((uint)Random.Next(1, 5))
|
|
|
|
|
- .Element(CreateBox(i.ToString()));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ table.Cell().RowSpan(4).Element(CreateBox("A"));
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().RowSpan(2).Element(CreateBox("B"));
|
|
|
|
|
+ table.Cell().Element(CreateBox("C"));
|
|
|
|
|
+ table.Cell().Element(CreateBox("D"));
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().RowSpan(2).Element(CreateBox("E"));
|
|
|
|
|
+ table.Cell().Element(CreateBox("F"));
|
|
|
|
|
+ table.Cell().Element(CreateBox("G"));
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ [Test]
|
|
|
|
|
+ public void TemperatureReport()
|
|
|
|
|
+ {
|
|
|
|
|
+ RenderingTest
|
|
|
|
|
+ .Create()
|
|
|
|
|
+ .ProducePdf()
|
|
|
|
|
+ .PageSize(PageSizes.A4)
|
|
|
|
|
+ .ShowResults()
|
|
|
|
|
+ .Render(container => GeneratePerformanceStructure(container, 100));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Test]
|
|
|
|
|
+ public void TemperatureReport_PerformanceTest()
|
|
|
|
|
+ {
|
|
|
|
|
+ RenderingTest
|
|
|
|
|
+ .Create()
|
|
|
|
|
+ .ProducePdf()
|
|
|
|
|
+ .PageSize(PageSizes.A4)
|
|
|
|
|
+ .MaxPages(10000)
|
|
|
|
|
+ .EnableCaching()
|
|
|
|
|
+ .EnableDebugging(false)
|
|
|
|
|
+ .ShowResults()
|
|
|
|
|
+ .Render(container => GeneratePerformanceStructure(container, 1000));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static void GeneratePerformanceStructure(IContainer container, int repeats)
|
|
|
|
|
+ {
|
|
|
|
|
+ container
|
|
|
|
|
+ .Padding(25)
|
|
|
|
|
+ .Box()
|
|
|
|
|
+ .Border(2)
|
|
|
|
|
+ .Table(table =>
|
|
|
|
|
+ {
|
|
|
|
|
+ table.ColumnsDefinition(columns =>
|
|
|
|
|
+ {
|
|
|
|
|
+ columns.ConstantColumn(100);
|
|
|
|
|
+ columns.RelativeColumn();
|
|
|
|
|
+ columns.ConstantColumn(100);
|
|
|
|
|
+ columns.RelativeColumn();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ foreach (var _ in Enumerable.Range(0, repeats))
|
|
|
|
|
+ {
|
|
|
|
|
+ table.Cell().RowSpan(3).LabelCell("Project");
|
|
|
|
|
+ table.Cell().RowSpan(3).ValueCell(Placeholders.Sentence());
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().LabelCell("Date");
|
|
|
|
|
+ table.Cell().ValueCell(Placeholders.ShortDate());
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().LabelCell("Report number");
|
|
|
|
|
+ table.Cell().ValueCell(Placeholders.Integer());
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().LabelCell("Inspector");
|
|
|
|
|
+ table.Cell().ValueCell("Marcin Ziąbek");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ColumnSpan(2).LabelCell("Morning weather");
|
|
|
|
|
+ table.Cell().ColumnSpan(2).LabelCell("Evening weather");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ValueCell("Time");
|
|
|
|
|
+ table.Cell().ValueCell("7:13");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ValueCell("Time");
|
|
|
|
|
+ table.Cell().ValueCell("18:25");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ValueCell("Description");
|
|
|
|
|
+ table.Cell().ValueCell("Sunny");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ValueCell("Description");
|
|
|
|
|
+ table.Cell().ValueCell("Windy");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ValueCell("Wind");
|
|
|
|
|
+ table.Cell().ValueCell("Mild");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ValueCell("Wind");
|
|
|
|
|
+ table.Cell().ValueCell("Strong");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ValueCell("Temperature");
|
|
|
|
|
+ table.Cell().ValueCell("17°C");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ValueCell("Temperature");
|
|
|
|
|
+ table.Cell().ValueCell("32°C");
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().LabelCell("Remarks");
|
|
|
|
|
+ table.Cell().ColumnSpan(3).ValueCell(Placeholders.Paragraph());
|
|
|
|
|
+
|
|
|
|
|
+ table.Cell().ColumnSpan(4).BorderBottom(2);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private Action<IContainer> CreateBox(string label)
|
|
private Action<IContainer> CreateBox(string label)
|
|
|
{
|
|
{
|
|
|
return container =>
|
|
return container =>
|
|
|
{
|
|
{
|
|
|
- var height = Random.Next(2, 7) * 25;
|
|
|
|
|
|
|
+ var height = Random.Next(2, 6) * 10;
|
|
|
|
|
|
|
|
container
|
|
container
|
|
|
- .Border(2)
|
|
|
|
|
.Background(Placeholders.BackgroundColor())
|
|
.Background(Placeholders.BackgroundColor())
|
|
|
- .Layers(layers =>
|
|
|
|
|
- {
|
|
|
|
|
- layers
|
|
|
|
|
- .PrimaryLayer()
|
|
|
|
|
- .AlignCenter()
|
|
|
|
|
- .AlignMiddle()
|
|
|
|
|
- .Height(height)
|
|
|
|
|
- .Width(80)
|
|
|
|
|
- .Border(1);
|
|
|
|
|
-
|
|
|
|
|
- layers
|
|
|
|
|
- .Layer()
|
|
|
|
|
- .AlignCenter()
|
|
|
|
|
- .AlignMiddle()
|
|
|
|
|
- .Text($"{label}: {height}px");
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // .AlignCenter()
|
|
|
|
|
+ // .AlignMiddle()
|
|
|
|
|
+ .Height(height);
|
|
|
|
|
+ // .Text($"{label}: {height}px");
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|