Program.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using QuestPDF;
  2. using QuestPDF.Companion;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. using QuestPDF.ReportSample;
  7. using QuestPDF.ReportSample.Layouts;
  8. Settings.License = LicenseType.Professional;
  9. //await RunGenericException();
  10. //await RunLayoutError();
  11. await RunSimpleDocument();
  12. //await RunReportDocument();
  13. Task RunGenericException()
  14. {
  15. return Document
  16. .Create(container =>
  17. {
  18. container.Page(page =>
  19. {
  20. page.Content()
  21. .PaddingVertical(1, Unit.Centimetre)
  22. .Column(x =>
  23. {
  24. x.Spacing(20);
  25. x.Item().Text(Placeholders.LoremIpsum());
  26. x.Item().Hyperlink("questpdf.com").Image(Placeholders.Image(200, 200));
  27. throw new Exception("New exception");
  28. });
  29. });
  30. })
  31. .ShowInCompanionAsync();
  32. }
  33. Task RunLayoutError()
  34. {
  35. return Document
  36. .Create(container =>
  37. {
  38. container.Page(page =>
  39. {
  40. page.Size(PageSizes.A4);
  41. page.Margin(2, Unit.Centimetre);
  42. page.PageColor(Colors.White);
  43. page.DefaultTextStyle(x => x.FontSize(20));
  44. page.Content()
  45. .PaddingVertical(1, Unit.Centimetre)
  46. .Column(x =>
  47. {
  48. x.Spacing(20);
  49. x.Item().Text(Placeholders.LoremIpsum());
  50. foreach (var i in Enumerable.Range(0, 15))
  51. {
  52. x.Item().Background(Colors.Grey.Lighten3).MaxWidth(200).Container().Width(100 + i * 10).Height(50).Text($"Item {i}");
  53. }
  54. });
  55. });
  56. })
  57. .ShowInCompanionAsync();
  58. }
  59. Task RunSimpleDocument()
  60. {
  61. return Document
  62. .Create(container =>
  63. {
  64. container.Page(page =>
  65. {
  66. page.Size(PageSizes.A4);
  67. page.Margin(2, Unit.Centimetre);
  68. page.PageColor(Colors.White);
  69. page.DefaultTextStyle(x => x.FontSize(20));
  70. page.Header()
  71. .Text("Hello PDF!")
  72. .SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
  73. page.Content()
  74. .PaddingVertical(1, Unit.Centimetre)
  75. .Column(x =>
  76. {
  77. x.Spacing(20);
  78. x.Item().Text(Placeholders.LoremIpsum());
  79. x.Item().Hyperlink("questpdf.com").Image(Placeholders.Image(200, 100));
  80. });
  81. page.Footer()
  82. .AlignCenter()
  83. .Text(x =>
  84. {
  85. x.Span("Page ");
  86. x.CurrentPageNumber();
  87. });
  88. });
  89. })
  90. .ShowInCompanionAsync();
  91. }
  92. Task RunReportDocument()
  93. {
  94. ImagePlaceholder.Solid = true;
  95. var model = DataSource.GetReport();
  96. var report = new StandardReport(model);
  97. return report.ShowInCompanionAsync();
  98. }