public void ItemTypes() { RenderingTest .Create() .ProducePdf() .PageSize(650, 300) .ShowResults() .Render(container => { container .Padding(25) .MinimalBox() .Border(1) .Column(column => { column.Item().LabelCell("Total width: 600px"); column.Item().Row(row => { row.ConstantItem(150).ValueCell("150px"); row.ConstantItem(100).ValueCell("100px"); row.RelativeItem(4).ValueCell("200px"); row.RelativeItem(3).ValueCell("150px"); }); column.Item().Row(row => { row.ConstantItem(100).ValueCell("100px"); row.ConstantItem(50).ValueCell("50px"); row.RelativeItem(2).ValueCell("100px"); row.RelativeItem(1).ValueCell("50px"); }); }); }); }
public void Overlapping() { RenderingTest .Create() .ProduceImages() .PageSize(170, 170) .ShowResults() .Render(container => { container .Padding(10) .MinimalBox() .Border(1) .Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); }); table.Cell().Row(1).RowSpan(3).Column(1).ColumnSpan(3).Background(Colors.Grey.Lighten3).MinHeight(150); table.Cell().Row(1).RowSpan(2).Column(1).ColumnSpan(2).Background(Colors.Grey.Lighten1).MinHeight(100); table.Cell().Row(3).Column(3).Background(Colors.Grey.Darken1).MinHeight(50); }); }); }
public void PagingSupport() { RenderingTest .Create() .ProducePdf() .PageSize(420, 220) .ShowResults() .Render(container => { container .Padding(10) .MinimalBox() .Border(1) .Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); }); // by using custom 'Element' method, we can reuse visual configuration table.Cell().Element(Block).Text(Placeholders.Label()); table.Cell().Element(Block).Text(Placeholders.Label()); table.Cell().Element(Block).Text(Placeholders.Paragraph()); table.Cell().Element(Block).Text(Placeholders.Label()); }); }); }
public void ColumnsDefinition() { RenderingTest .Create() .ProduceImages() .PageSize(320, 80) .ShowResults() .Render(container => { container .Padding(10) .Table(table => { table.ColumnsDefinition(columns => { columns.ConstantColumn(50); columns.ConstantColumn(100); columns.RelativeColumn(2); columns.RelativeColumn(3); }); table.Cell().ColumnSpan(4).LabelCell("Total width: 300px"); table.Cell().ValueCell("50px"); table.Cell().ValueCell("100px"); table.Cell().ValueCell("100px"); table.Cell().ValueCell("150px"); }); }); }
public void ExtendLastCellsToTableBottom() { RenderingTest .Create() .ProduceImages() .PageSize(220, 170) .ShowResults() .Render(container => { container .Padding(10) .MinimalBox() .Border(1) .Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); }); table.ExtendLastCellsToTableBottom(); table.Cell().Row(1).Column(1).Element(Block).Text("A"); table.Cell().Row(3).Column(1).Element(Block).Text("B"); table.Cell().Row(2).Column(2).Element(Block).Text("C"); table.Cell().Row(3).Column(3).Element(Block).Text("D"); table.Cell().Row(2).RowSpan(2).Column(4).Element(Block).Text("E"); }); }); }
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()); } });
public void Example() { RenderingTest .Create() .PageSize(400, 300) .ProduceImages() .ShowResults() .Render(container => { container .DefaultTextStyle(TextStyle.Default.Size(18)) .Padding(25) .Row(row => { row.Spacing(25); row.RelativeItem() .Border(1) .Padding(15) .Background(Colors.Grey.Lighten2) .Text("Lorem ipsum"); row.RelativeItem() .Border(1) .Background(Colors.Grey.Lighten2) .Padding(15) .Text("dolor sit amet"); }); }); }
public void CustomElement() { RenderingTest .Create() .PageSize(500, 200) .ProduceImages() .ShowResults() .Render(container => { container .Padding(5) .MinimalBox() .Border(1) .Padding(10) .Text(text => { text.DefaultTextStyle(TextStyle.Default.FontSize(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("."); }); }); }
public void TextElements() { RenderingTest .Create() .PageSize(PageSizes.A4) .ProducePdf() .ShowResults() .Render(container => { container .Padding(20) .Padding(10) .MinimalBox() .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? <").Underline(); }); }); }
public void BreakingLongWord() { RenderingTest .Create() .ProduceImages() .ShowResults() .RenderDocument(container => { container.Page(page => { page.Margin(50); page.PageColor(Colors.White); page.Size(PageSizes.A4); page.Content().Column(column => { column.Item().Text(null); column.Item().Text(text => { text.DefaultTextStyle(x => x.BackgroundColor(Colors.Red.Lighten3).FontSize(24)); text.Span(" " + Placeholders.LoremIpsum()); text.Span(" 0123456789012345678901234567890123456789012345678901234567890123456789 ").WrapAnywhere(); }); }); }); }); }
public void ParagraphSpacing() { RenderingTest .Create() .PageSize(500, 300) .ProduceImages() .ShowResults() .Render(container => { container .Padding(5) .MinimalBox() .Border(1) .Padding(10) .Text(text => { text.ParagraphSpacing(10); foreach (var i in Enumerable.Range(1, 3)) { text.Span($"Paragraph {i}: ").SemiBold(); text.Line(Placeholders.Paragraph()); } }); }); }
public void DrawingNullTextShouldNotThrowException() { RenderingTest .Create() .ProduceImages() .ShowResults() .RenderDocument(container => { container.Page(page => { page.Margin(50); page.PageColor(Colors.White); page.Size(PageSizes.A4); page.Content().Column(column => { column.Item().Text(null); column.Item().Text(text => { text.Span(null); text.Line(null); text.Hyperlink(null, "http://www.questpdf.com"); text.TotalPages().Format(x => null); }); }); }); }); }
public void Textcolumn() { RenderingTest .Create() .PageSize(PageSizes.A4) .ProducePdf() .ShowResults() .Render(container => { container .Padding(20) .Padding(10) .MinimalBox() .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()}"); } }); }); }
public void Stability() { // up to version 2021.12, this code would always result with the infinite layout exception RenderingTest .Create() .ProducePdf() .MaxPages(100) .PageSize(250, 150) .ShowResults() .Render(container => { container .Padding(25) .Row(row => { row.RelativeItem().Column(column => { column.Item().ShowOnce().Element(CreateBox).Text("X"); column.Item().Element(CreateBox).Text("1"); column.Item().Element(CreateBox).Text("2"); }); row.RelativeItem().Column(column => { column.Item().Element(CreateBox).Text("1"); column.Item().Element(CreateBox).Text("2"); }); }); });
public void Unconstrained() { RenderingTest .Create() .PageSize(400, 350) .Render(container => { container .Padding(25) .PaddingLeft(50) .Column(column => { column.Item().Width(300).Height(150).Background(Colors.Blue.Lighten4); column .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); column.Item().Width(300).Height(150).Background(Colors.Blue.Lighten3); }); }); }
public void DefaultTextStyle() { RenderingTest .Create() .ProducePdf() .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.PageColor(Colors.White); page.Content().Column(column => { column.Item().Text(Placeholders.Sentence()); column.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()).FontColor(Colors.Red.Medium); }); }); }); }); }
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() .RenderDocument(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); } } }
public void ScaleToFit() { RenderingTest .Create() .PageSize(PageSizes.A4) .ProduceImages() .ShowResults() .Render(container => { container.Padding(25).Column(column => { var text = Placeholders.Paragraph(); foreach (var i in Enumerable.Range(2, 5)) { column .Item() .MinimalBox() .Border(1) .Padding(5) .Width(i * 40) .Height(i * 20) .ScaleToFit() .Text(text); } }); }); }
public void SkipOnce() { RenderingTest .Create() .ProduceImages() .ShowResults() .RenderDocument(container => { container.Page(page => { page.Margin(20); page.Size(PageSizes.A7.Landscape()); page.PageColor(Colors.White); page.Header().Column(column => { column.Item().ShowOnce().Text("This header is visible on the first page."); column.Item().SkipOnce().Text("This header is visible on the second page and all following."); }); page.Content() .PaddingVertical(10) .Text(Placeholders.Paragraphs()) .FontColor(Colors.Grey.Medium); page.Footer().Text(text => { text.Span("Page "); text.CurrentPageNumber(); text.Span(" out of "); text.TotalPages(); }); }); }); }
public void GridExample() { 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); }); }); }
public void Example2() { RenderingTest .Create() .PageSize(200, 200) .ProduceImages() .ShowResults() .Render(container => { container .Padding(25) .Border(2) .Width(150) .Height(150) .Background(Colors.Blue.Lighten2) .PaddingTop(50) .Background(Colors.Green.Lighten2) .PaddingRight(50) .Background(Colors.Red.Lighten2) .PaddingBottom(50) .Background(Colors.Amber.Lighten2) .PaddingLeft(50) .Background(Colors.Grey.Lighten2); }); }
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); }); }); }
public void PartialAutoPlacement() { RenderingTest .Create() .ProduceImages() .PageSize(220, 220) .ShowResults() .Render(container => { container .Padding(10) .MinimalBox() .Border(1) .Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); }); table.Cell().Element(Block).Text("A"); table.Cell().Row(2).Column(2).Element(Block).Text("B"); table.Cell().Element(Block).Text("C"); table.Cell().Row(3).Column(3).Element(Block).Text("D"); table.Cell().ColumnSpan(2).Element(Block).Text("E"); }); }); }
public void Decoration() { RenderingTest .Create() .PageSize(300, 300) .Render(container => { container .Background("#FFF") .Padding(25) .Decoration(decoration => { decoration .Before() .Background(Colors.Grey.Medium) .Padding(10) .Text("Notes") .FontSize(16) .FontColor("#FFF"); decoration .Content() .Background(Colors.Grey.Lighten3) .Padding(10) .ExtendVertical() .Text(Helpers.Placeholders.LoremIpsum()); }); }); }
public void BasicPlacement() { RenderingTest .Create() .ProduceImages() .PageSize(220, 220) .ShowResults() .Render(container => { container .Padding(10) .MinimalBox() .Border(1) .Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); }); // by using custom 'Element' method, we can reuse visual configuration table.Cell().Row(1).Column(4).Element(Block).Text("A"); table.Cell().Row(2).Column(2).Element(Block).Text("B"); table.Cell().Row(3).Column(3).Element(Block).Text("C"); table.Cell().Row(4).Column(1).Element(Block).Text("D"); }); }); }
public void Translate() { RenderingTest .Create() .PageSize(300, 200) .Render(container => { container .Background("#FFF") .MinimalBox() .Padding(25) .Background(Colors.Green.Lighten3) .TranslateX(15) .TranslateY(15) .Border(2) .BorderColor(Colors.Green.Darken1) .Padding(50) .Text("Moved text") .FontSize(25); }); }
public void Stability() { RenderingTest .Create() .ProduceImages() .PageSize(300, 300) .ShowResults() .Render(container => { container .Padding(10) .Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); }); table.Cell().RowSpan(4).Element(Block).Text("1"); table.Cell().RowSpan(2).Element(Block).Text("2"); table.Cell().RowSpan(1).Element(Block).Text("3"); table.Cell().RowSpan(1).Element(Block).Text("4"); table.Cell().RowSpan(2).Element(Block).Text("5"); table.Cell().RowSpan(1).Element(Block).Text("6"); table.Cell().RowSpan(1).Element(Block).Text("7"); }); }); }
public void FreeRotateCenter() { RenderingTest .Create() .PageSize(300, 300) .Render(container => { container .Padding(25) .Background(Colors.Grey.Lighten2) .AlignCenter() .AlignMiddle() .Background(Colors.White) .TranslateX(50) .TranslateY(50) .Rotate(30) .TranslateX(-50) .TranslateY(-50) .Width(100) .Height(100) .Background(Colors.Blue.Medium); }); }
public void DefaultCellStyle() { RenderingTest .Create() .ProduceImages() .PageSize(220, 120) .ShowResults() .Render(container => { container .Padding(10) .MinimalBox() .Border(1) .DefaultTextStyle(TextStyle.Default.Size(16)) .Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); columns.RelativeColumn(); }); table.Cell().Row(1).Column(1).Element(Block).Text("A"); table.Cell().Row(2).Column(2).Element(Block).Text("B"); table.Cell().Row(1).Column(3).Element(Block).Text("C"); table.Cell().Row(2).Column(4).Element(Block).Text("D"); }); }); }
public void LoremPicsum() { RenderingTest .Create() .PageSize(350, 280) .ProducePdf() .ShowResults() .Render(container => { container .Background("#FFF") .Padding(25) .Column(column => { column.Spacing(10); column .Item() .Component(new LoremPicsum(true)); column .Item() .AlignRight() .Text("From Lorem Picsum"); }); }); }