2021-01-16 01:31:39 +01:00
|
|
|
using QuestPDF.Examples.Engine;
|
|
|
|
|
using QuestPDF.Fluent;
|
|
|
|
|
using QuestPDF.Infrastructure;
|
2021-04-17 21:51:17 +02:00
|
|
|
using SkiaSharp;
|
2021-01-16 01:31:39 +01:00
|
|
|
|
|
|
|
|
namespace QuestPDF.Examples
|
|
|
|
|
{
|
|
|
|
|
public class ElementExamples : ExampleTestBase
|
|
|
|
|
{
|
|
|
|
|
//[ShowResult]
|
|
|
|
|
[ImageSize(200, 150)]
|
|
|
|
|
public void Placeholder(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
container
|
|
|
|
|
.Background("#FFF")
|
|
|
|
|
.Padding(25)
|
|
|
|
|
.Placeholder();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-16 01:19:34 +02:00
|
|
|
//[ShowResult]
|
2021-01-16 01:31:39 +01:00
|
|
|
[ImageSize(300, 300)]
|
2021-05-02 21:11:08 +02:00
|
|
|
public void Decoration(IContainer container)
|
2021-01-16 01:31:39 +01:00
|
|
|
{
|
|
|
|
|
container
|
|
|
|
|
.Background("#FFF")
|
|
|
|
|
.Padding(25)
|
2021-05-02 21:11:08 +02:00
|
|
|
.Decoration(decoration =>
|
2021-01-16 01:31:39 +01:00
|
|
|
{
|
2021-05-02 21:11:08 +02:00
|
|
|
decoration
|
2021-01-16 01:31:39 +01:00
|
|
|
.Header()
|
|
|
|
|
.Background("#888")
|
|
|
|
|
.Padding(10)
|
|
|
|
|
.Text("Notes", TextStyle.Default.Size(16).Color("#FFF"));
|
|
|
|
|
|
2021-05-02 21:11:08 +02:00
|
|
|
decoration
|
2021-01-16 01:31:39 +01:00
|
|
|
.Content()
|
|
|
|
|
.Background("#DDD")
|
|
|
|
|
.Padding(10)
|
|
|
|
|
.ExtendVertical()
|
2021-04-18 23:11:29 +02:00
|
|
|
.Text(Helpers.Placeholders.LoremIpsum());
|
2021-01-16 01:31:39 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[ShowResult]
|
|
|
|
|
[ImageSize(298, 421)]
|
|
|
|
|
public void Page(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
container
|
|
|
|
|
.Background("#FFF")
|
|
|
|
|
.Padding(15)
|
|
|
|
|
.Page(page =>
|
|
|
|
|
{
|
|
|
|
|
page.Header()
|
|
|
|
|
.Height(60)
|
|
|
|
|
.Background("#BBB")
|
|
|
|
|
.AlignCenter()
|
|
|
|
|
.AlignMiddle()
|
|
|
|
|
.Text("Header");
|
|
|
|
|
|
|
|
|
|
page.Content()
|
|
|
|
|
.Background("#DDD")
|
|
|
|
|
.AlignCenter()
|
|
|
|
|
.AlignMiddle()
|
|
|
|
|
.Text("Content");
|
|
|
|
|
|
|
|
|
|
page.Footer()
|
|
|
|
|
.Height(30)
|
|
|
|
|
.Background("#BBB")
|
|
|
|
|
.AlignCenter()
|
|
|
|
|
.AlignMiddle()
|
|
|
|
|
.Text("Footer");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[ShowResult]
|
|
|
|
|
[ImageSize(740, 200)]
|
|
|
|
|
public void Row(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
container
|
|
|
|
|
.Background("#FFF")
|
|
|
|
|
.Padding(20)
|
|
|
|
|
.Stack(stack =>
|
|
|
|
|
{
|
2021-05-01 22:46:37 +02:00
|
|
|
stack.Item()
|
2021-01-16 01:31:39 +01:00
|
|
|
.PaddingBottom(10)
|
|
|
|
|
.AlignCenter()
|
|
|
|
|
.Text("This Row element is 700pt wide");
|
|
|
|
|
|
2021-05-01 22:46:37 +02:00
|
|
|
stack.Item().Row(row =>
|
2021-01-16 01:31:39 +01:00
|
|
|
{
|
|
|
|
|
row.ConstantColumn(100)
|
|
|
|
|
.Background("#DDD")
|
|
|
|
|
.Padding(10)
|
|
|
|
|
.ExtendVertical()
|
|
|
|
|
.Text("This column is 100 pt wide");
|
|
|
|
|
|
|
|
|
|
row.RelativeColumn()
|
|
|
|
|
.Background("#BBB")
|
|
|
|
|
.Padding(10)
|
|
|
|
|
.Text("This column takes 1/3 of the available space (200pt)");
|
|
|
|
|
|
|
|
|
|
row.RelativeColumn(2)
|
|
|
|
|
.Background("#DDD")
|
|
|
|
|
.Padding(10)
|
|
|
|
|
.Text("This column takes 2/3 of the available space (400pt)");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[ShowResult]
|
|
|
|
|
[ImageSize(500, 350)]
|
|
|
|
|
public void Column(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
container
|
|
|
|
|
.Background("#FFF")
|
|
|
|
|
.Padding(15)
|
|
|
|
|
.Stack(column =>
|
|
|
|
|
{
|
|
|
|
|
column.Spacing(10);
|
|
|
|
|
|
|
|
|
|
column
|
2021-05-01 22:46:37 +02:00
|
|
|
.Item()
|
2021-01-16 01:31:39 +01:00
|
|
|
.Background("#999")
|
|
|
|
|
.Height(50);
|
|
|
|
|
|
|
|
|
|
column
|
2021-05-01 22:46:37 +02:00
|
|
|
.Item()
|
2021-01-16 01:31:39 +01:00
|
|
|
.Background("#BBB")
|
|
|
|
|
.Height(100);
|
|
|
|
|
|
|
|
|
|
column
|
2021-05-01 22:46:37 +02:00
|
|
|
.Item()
|
2021-01-16 01:31:39 +01:00
|
|
|
.Background("#DDD")
|
|
|
|
|
.Height(150);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-23 14:43:03 +01:00
|
|
|
|
|
|
|
|
//[ShowResult]
|
|
|
|
|
[ImageSize(300, 200)]
|
|
|
|
|
public void Debug(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
container
|
|
|
|
|
.Padding(25)
|
|
|
|
|
.Debug()
|
|
|
|
|
.Padding(-5)
|
|
|
|
|
.Row(row =>
|
|
|
|
|
{
|
|
|
|
|
row.RelativeColumn().Padding(5).Extend().Placeholder();
|
|
|
|
|
row.RelativeColumn().Padding(5).Extend().Placeholder();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 17:49:19 +02:00
|
|
|
//[ShowResult]
|
2021-03-23 14:43:03 +01:00
|
|
|
[ImageSize(300, 200)]
|
|
|
|
|
public void ElementEnd(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
var text = "";
|
|
|
|
|
|
|
|
|
|
container
|
|
|
|
|
.Padding(10)
|
|
|
|
|
.Element(x =>
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(text))
|
|
|
|
|
x.Height(10).Width(50).Background("#DDD");
|
|
|
|
|
else
|
|
|
|
|
x.Text(text);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-28 17:49:19 +02:00
|
|
|
|
2021-04-03 00:13:14 +02:00
|
|
|
//[ShowResult]
|
2021-03-28 17:49:19 +02:00
|
|
|
[ImageSize(300, 200)]
|
|
|
|
|
public void GridExample(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
var textStyle = TextStyle.Default.Size(14);
|
|
|
|
|
|
|
|
|
|
container
|
|
|
|
|
.Padding(20)
|
|
|
|
|
.AlignRight()
|
|
|
|
|
.Grid(grid =>
|
|
|
|
|
{
|
|
|
|
|
grid.Spacing(5);
|
|
|
|
|
grid.Columns(12);
|
|
|
|
|
|
2021-05-02 21:11:08 +02:00
|
|
|
grid.Item(8).Background("#DDD").Height(50).Padding(5).Text("This is a short text", textStyle);
|
|
|
|
|
grid.Item(4).Background("#BBB").Padding(5).Text("Showing how to...", textStyle);
|
|
|
|
|
grid.Item(2).Background("#999").Height(50);
|
|
|
|
|
grid.Item(4).Background("#AAA").Border(2).BorderColor("#666").Padding(5).Text("...generate", textStyle);
|
|
|
|
|
grid.Item(6).Background("#CCC").Padding(5).Text("simple grids", textStyle.Size(18).Bold());
|
|
|
|
|
grid.Item(8).Background("#DDD").Height(50);
|
2021-03-28 17:49:19 +02:00
|
|
|
});
|
|
|
|
|
}
|
2021-04-16 01:19:34 +02:00
|
|
|
|
|
|
|
|
[ShowResult]
|
|
|
|
|
[ImageSize(300, 300)]
|
|
|
|
|
public void Layers(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
container
|
|
|
|
|
.Background("#FFF")
|
|
|
|
|
.Padding(25)
|
|
|
|
|
.Layers(layers =>
|
|
|
|
|
{
|
|
|
|
|
layers.Layer().Text("Something else");
|
|
|
|
|
|
|
|
|
|
layers.PrimaryLayer().Stack(stack =>
|
|
|
|
|
{
|
2021-05-01 22:46:37 +02:00
|
|
|
stack.Item().PaddingTop(20).Text("Text 1");
|
|
|
|
|
stack.Item().PaddingTop(40).Text("Text 2");
|
2021-04-16 01:19:34 +02:00
|
|
|
});
|
|
|
|
|
|
2021-04-17 21:51:17 +02:00
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-16 01:19:34 +02:00
|
|
|
layers.Layer().Background("#8F00").Extend();
|
2021-04-21 23:44:15 +02:00
|
|
|
layers.Layer().PaddingTop(40).Text("It works!", TextStyle.Default.Size(24));
|
2021-04-16 01:19:34 +02:00
|
|
|
});
|
|
|
|
|
}
|
2021-01-16 01:31:39 +01:00
|
|
|
}
|
2021-04-21 23:44:15 +02:00
|
|
|
}
|