| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using System.Linq;
- using NUnit.Framework;
- using QuestPDF.Examples.Engine;
- using QuestPDF.Fluent;
- using QuestPDF.Helpers;
- using QuestPDF.Infrastructure;
- namespace QuestPDF.Examples;
- public class ContentOverflowVisualizationExamples
- {
- [Test]
- public void DrawOverflow()
- {
- RenderingTest
- .Create()
- .ShowResults()
- .ProducePdf()
- .EnableDebugging()
- .RenderDocument(document =>
- {
- document.Page(page =>
- {
- page.Size(PageSizes.A4);
- page.Margin(24);
- page.DefaultTextStyle(TextStyle.Default.FontSize(16));
- page.Header().Text("Document header").FontSize(24).Bold().FontColor(Colors.Blue.Accent2);
- page.Content().PaddingVertical(24).Column(column =>
- {
- column.Spacing(16);
- foreach (var size in Enumerable.Range(20, 20))
- column.Item().Width(size * 10).Height(40).Background(Colors.Grey.Lighten3);
-
- column.Item().Row(row =>
- {
- row.RelativeItem().Border(1).Background(Colors.Grey.Lighten3).Padding(5).Text("Will it work?").FontSize(20);
- row.RelativeItem().Border(1).Background(Colors.Grey.Lighten3).Padding(5).Height(100).ShowEntire().Text(Placeholders.LoremIpsum()).FontSize(20);
- });
-
- foreach (var size in Enumerable.Range(20, 20))
- column.Item().Width(size * 10).Height(40).Background(Colors.Grey.Lighten3);
- });
-
- page.Footer().AlignCenter().Text(text =>
- {
- text.CurrentPageNumber();
- text.Span(" / ");
- text.TotalPages();
- });
- });
- });
- }
-
- [Test]
- public void DrawOverflowRealExample()
- {
- var image = Placeholders.Image(400, 300);
-
- RenderingTest
- .Create()
- .ShowResults()
- .PageSize(PageSizes.A4)
- .ProducePdf()
- .EnableDebugging()
- .Render(container =>
- {
- container.Column(column =>
- {
- foreach (var i in Enumerable.Range(0, 50))
- column.Item().Height(30).Width(i * 5 + 100).Background(Placeholders.BackgroundColor());
-
- column.Item()
- .Padding(24)
- // constrain area to square 200 x 200
- .Width(200)
- .Height(200)
- .Background(Colors.Grey.Lighten3)
- // draw image that fits height (and therefore will overflow)
- //.ContentOverflowDebugArea()
- .Image(image)
- .FitHeight();
-
- foreach (var i in Enumerable.Range(0, 50))
- column.Item().Height(30).Width(i * 5 + 100).Background(Placeholders.BackgroundColor());
- });
- });
- }
-
- [Test]
- public void DrawOverflowSimpleExample()
- {
- var image = Placeholders.Image(400, 300);
-
- RenderingTest
- .Create()
- .ShowResults()
- .PageSize(PageSizes.A4)
- .EnableDebugging()
- .ProducePdf()
- .Render(container =>
- {
- container
- .Padding(24)
- // constrain area to square 200 x 200
- .Width(200)
- .Height(200)
- .Background(Colors.Grey.Lighten3)
- // draw image that fits height (and therefore will overflow)
- //.ContentOverflowDebugArea()
- .Image(image)
- .FitHeight();
- });
- }
-
- [Test]
- public void DrawOverflowCases()
- {
- RenderingTest
- .Create()
- .ShowResults()
- .PageSize(PageSizes.A4)
- .EnableDebugging()
- .ProducePdf()
- .Render(container =>
- {
- container.Padding(24).Row(row =>
- {
- row.Spacing(50);
-
- row.RelativeItem().ContentFromLeftToRight().Element(GenerateOverflowPatterns);
- row.RelativeItem().ContentFromRightToLeft().Element(GenerateOverflowPatterns);
- });
- void GenerateOverflowPatterns(IContainer container)
- {
- container.Column(column =>
- {
- column.Spacing(50);
- column
- .Item()
- .Element(DrawTestcaseArea)
-
- .Width(50)
- .Height(150)
-
- .Text("Test");
-
- column
- .Item()
- .Element(DrawTestcaseArea)
-
- .Width(150)
- .Height(50)
-
- .Text("Test");
-
- column
- .Item()
- .Element(DrawTestcaseArea)
- .Width(200)
- .Height(150)
-
- .Text("Test");
- IContainer DrawTestcaseArea(IContainer container)
- {
- return container
- .Height(200)
- .Background(Colors.Grey.Lighten4)
- .Width(100)
- .Height(100)
- .Background(Colors.Grey.Lighten1);
- }
- });
- }
- });
- }
- }
|