| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using QuestPDF;
- using QuestPDF.Companion;
- using QuestPDF.Fluent;
- using QuestPDF.Helpers;
- using QuestPDF.Infrastructure;
- using QuestPDF.ReportSample;
- using QuestPDF.ReportSample.Layouts;
- Settings.License = LicenseType.Professional;
- var sw = System.Diagnostics.Stopwatch.StartNew();
- foreach (var i in Enumerable.Range(0, 1000))
- {
- Document
- .Create(document =>
- {
- foreach (var j in Enumerable.Range(0, 20))
- {
- document.Page(page =>
- {
- page.Margin(50);
- page.Content().Text(text =>
- {
- text.Span("Hello world from ");
- text.Span(j.ToString()).FontColor(Colors.Red.Medium);
- text.Span(" iteration!");
- });
- });
- }
- })
- .GeneratePdf();
- }
- sw.Stop();
- Console.WriteLine($"Total time for 1000 documents: {sw.ElapsedMilliseconds} ms");
- return;
- //await RunGenericException();
- //await RunLayoutError();
- await RunSimpleDocument();
- //await RunReportDocument();
- //await RunDocumentWithMultiplePages();
- Task RunGenericException()
- {
- return Document
- .Create(container =>
- {
- container.Page(page =>
- {
- page.Content()
- .PaddingVertical(1, Unit.Centimetre)
- .Column(x =>
- {
- x.Spacing(20);
- x.Item().Text(Placeholders.LoremIpsum());
- x.Item().Hyperlink("questpdf.com").Image(Placeholders.Image(300, 200));
- throw new Exception("New exception");
- });
- });
- })
- .ShowInCompanionAsync();
- }
- Task RunLayoutError()
- {
- return Document
- .Create(container =>
- {
- container.Page(page =>
- {
- page.Size(PageSizes.A4);
- page.Margin(2, Unit.Centimetre);
- page.PageColor(Colors.White);
- page.DefaultTextStyle(x => x.FontSize(20));
- page.Content()
- .PaddingVertical(1, Unit.Centimetre)
- .Column(x =>
- {
- x.Spacing(20);
-
- x.Item().Text(Placeholders.LoremIpsum());
-
- foreach (var i in Enumerable.Range(0, 15))
- {
- x.Item().Background(Colors.Grey.Lighten3).MaxWidth(200).Container().Width(100 + i * 10).Height(50).Text($"Item {i}");
- }
- });
- });
- })
- .ShowInCompanionAsync();
- }
- Task RunSimpleDocument()
- {
- return Document
- .Create(container =>
- {
- container.Page(page =>
- {
- page.Size(PageSizes.A4);
- page.Margin(2, Unit.Centimetre);
- page.PageColor(Colors.White);
- page.DefaultTextStyle(x => x.FontSize(20));
-
- page.Header()
- .Text("Hello PDF!")
- .SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
-
- page.Content()
- .PaddingVertical(1, Unit.Centimetre)
- .Column(x =>
- {
- x.Spacing(20);
-
- x.Item().Text(Placeholders.LoremIpsum());
- x.Item().Hyperlink("questpdf.com").Image(Placeholders.Image(200, 100));
- });
-
- page.Footer()
- .AlignCenter()
- .Text(x =>
- {
- x.Span("Page ");
- x.CurrentPageNumber();
- });
- });
- })
- .ShowInCompanionAsync();
- }
- Task RunReportDocument()
- {
- ImagePlaceholder.Solid = true;
-
- var model = DataSource.GetReport();
- var report = new StandardReport(model);
- return report.ShowInCompanionAsync();
- }
- Task RunDocumentWithMultiplePages()
- {
- return Document
- .Create(document =>
- {
- foreach (var i in Enumerable.Range(10, 10))
- {
- document.Page(page =>
- {
- page.Size(new PageSize(i * 20, i * 30));
- page.Margin(20);
- page.Content().Background(Placeholders.BackgroundColor());
- });
- }
- })
- .ShowInCompanionAsync();
- }
- Task RunMergedDocument()
- {
- var document1 = Document
- .Create(container =>
- {
- container.Page(page =>
- {
- page.Content()
- .Text("Page 1!")
- .SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
- });
- });
- var document2 = Document
- .Create(container =>
- {
- container.Page(page =>
- {
- page.Content()
- .Text("Page 2!")
- .SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
- });
- });
- var mergedDocument = Document.Merge(document1, document2);
- return mergedDocument.ShowInCompanionAsync();
- }
|