| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using System;
- using System.Linq;
- using NUnit.Framework;
- using QuestPDF.Examples.Engine;
- using QuestPDF.Fluent;
- using QuestPDF.Helpers;
- using QuestPDF.Infrastructure;
- namespace QuestPDF.Examples
- {
- public class ColumnExamples
- {
- [Test]
- public void Column()
- {
- RenderingTest
- .Create()
- .PageSize(PageSizes.A4)
- .ShowResults()
- .ProducePdf()
- .Render(container =>
- {
- container.Column(column =>
- {
- foreach (var i in Enumerable.Range(0, 10))
- column.Item().Element(Block);
- static void Block(IContainer container)
- {
- container
- .Width(72)
- .Height(3.5f, Unit.Inch)
- .Height(1.5f, Unit.Inch)
- .Background(Placeholders.BackgroundColor());
- }
- });
- });
- }
-
- [Test]
- public void ColumnDoesNotPutDoubleSpacingWhenChildIsEmpty()
- {
- RenderingTest
- .Create()
- .PageSize(PageSizes.A4)
- .ShowResults()
- .ProducePdf()
- .Render(container =>
- {
- container.Padding(50).Shrink().Border(1).Background(Colors.Grey.Lighten3).Column(column =>
- {
- column.Spacing(30);
-
- column.Item();
- column.Item();
- column.Item();
-
- foreach (var i in Enumerable.Range(0, 5))
- {
- column.Item().Element(Block);
- column.Item().Element(Block);
- column.Item().Element(Block);
-
- column.Item();
-
- column.Item().Element(Block);
- column.Item().Element(Block);
- column.Item().Element(Block);
- column.Item().Element(Block);
-
- column.Item();
- column.Item();
-
- column.Item().Element(Block);
- column.Item().Element(Block);
-
- column.Item();
- column.Item();
- }
-
- static void Block(IContainer container)
- {
- container
- .Width(100)
- .Height(30)
- .Background(Placeholders.Color());
- }
- });
- });
- }
-
- [Test]
- public void Stability_NoItems()
- {
- RenderingTest
- .Create()
- .ProducePdf()
- .MaxPages(100)
- .PageSize(250, 150)
- .Render(container =>
- {
- container
- .Padding(25)
- .Column(column => { });
- });
- }
-
- [Test]
- public void ColumnWithShowOnce()
- {
- RenderingTest
- .Create()
- .ProducePdf()
- .MaxPages(100)
- .ShowResults()
- .RenderDocument(document =>
- {
- document.Page(page =>
- {
- page.Size(PageSizes.A4);
- page.Margin(50);
- page.Content().PaddingVertical(25).Column(column =>
- {
- column.Spacing(25);
-
- foreach (var i in Enumerable.Range(0, 50))
- column.Item().Height(75).Width(100 + i * 5).Background(Colors.Grey.Lighten2);
- });
- page.Header().Background(Colors.Grey.Lighten2).Column(column =>
- {
- column.Spacing(10);
- column.Item().Background(Colors.Red.Lighten3).Text("First line");
- column.Item().Background(Colors.Green.Lighten3).ShowIf(x => x.PageNumber % 3 != 0).Text("Second line");
- column.Item().Background(Colors.Blue.Lighten3).ShowIf(x => x.PageNumber % 2 != 0).Text("Third line");
- });
- });
- });
- }
-
- [Test]
- public void ColumnWithPageBreak()
- {
- RenderingTest
- .Create()
- .ProducePdf()
- .MaxPages(100)
- .ShowResults()
- .RenderDocument(document =>
- {
- document.Page(page =>
- {
- page.Size(PageSizes.A4);
- page.Margin(50);
- page.Content().PaddingVertical(25).Column(column =>
- {
- column.Spacing(25);
- foreach (var i in Enumerable.Range(1, 5))
- {
- foreach (var j in Enumerable.Range(1, i))
- column.Item().Height(75).Width(100 + i * 5).Background(Colors.Grey.Lighten2);
-
- if (i != 5)
- column.Item().PageBreak();
- }
- });
- });
- });
- }
- }
- }
|