PageBackgroundForegroundExample.cs 4.3 KB

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