PageBackgroundForegroundExample.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Linq;
  2. using NUnit.Framework;
  3. using QuestPDF.Examples.Engine;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Helpers;
  6. using QuestPDF.Infrastructure;
  7. namespace QuestPDF.Examples
  8. {
  9. public class PageBackgroundForegroundExample
  10. {
  11. [Test]
  12. public void PageBackgroundForeground()
  13. {
  14. RenderingTest
  15. .Create()
  16. .ProduceImages()
  17. .MaxPages(100)
  18. .ShowResults()
  19. .RenderDocument(document =>
  20. {
  21. document.Page(page =>
  22. {
  23. page.Size(PageSizes.A4);
  24. page.Margin(1, Unit.Inch);
  25. page.DefaultTextStyle(TextStyle.Default.FontSize(16));
  26. page.PageColor(Colors.White);
  27. const string transparentBlue = "#662196f3";
  28. page.Background()
  29. .AlignTop()
  30. .ExtendHorizontal()
  31. .Height(200)
  32. .Background(transparentBlue);
  33. page.Foreground()
  34. .AlignBottom()
  35. .ExtendHorizontal()
  36. .Height(250)
  37. .Background(transparentBlue);
  38. page.Header().Text("Background and foreground").Bold().FontColor(Colors.Blue.Darken2).FontSize(36);
  39. page.Content().PaddingVertical(25).Column(column =>
  40. {
  41. column.Spacing(25);
  42. foreach (var i in Enumerable.Range(0, 100))
  43. column.Item().Background(Colors.Grey.Lighten2).Height(75);
  44. });
  45. });
  46. });
  47. }
  48. [Test]
  49. public void CustomContentOnPageSides()
  50. {
  51. RenderingTest
  52. .Create()
  53. .ProduceImages()
  54. .MaxPages(100)
  55. .ShowResults()
  56. .RenderDocument(document =>
  57. {
  58. document.Page(page =>
  59. {
  60. const float horizontalMargin = 1.5f;
  61. const float verticalMargin = 1f;
  62. page.Size(PageSizes.A4);
  63. page.MarginVertical(verticalMargin, Unit.Inch);
  64. page.MarginHorizontal(horizontalMargin, Unit.Inch);
  65. page.PageColor(Colors.White);
  66. page.Background()
  67. .PaddingVertical(verticalMargin, Unit.Inch)
  68. .RotateRight()
  69. .Decoration(decoration =>
  70. {
  71. decoration.Before().RotateRight().RotateRight().Element(DrawSide);
  72. decoration.Content().Extend();
  73. decoration.After().Element(DrawSide);
  74. void DrawSide(IContainer container)
  75. {
  76. container
  77. .Height(horizontalMargin, Unit.Inch)
  78. .AlignMiddle()
  79. .Row(row =>
  80. {
  81. row.AutoItem().PaddingRight(16).Text("COMPANY NAME").FontSize(16).FontColor(Colors.Red.Medium);
  82. row.RelativeItem().PaddingTop(12).ExtendHorizontal().LineHorizontal(2).LineColor(Colors.Red.Medium);
  83. });
  84. }
  85. });
  86. page.Content().Column(column =>
  87. {
  88. column.Spacing(25);
  89. foreach (var i in Enumerable.Range(1, 100))
  90. column.Item().Background(Colors.Grey.Lighten2).Height(75).AlignCenter().AlignMiddle().Text(i.ToString()).FontSize(16);
  91. });
  92. });
  93. });
  94. }
  95. }
  96. }