ComponentExamples.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. internal class MyComponent : IComponent
  10. {
  11. public ISlot Header { get; set; }
  12. public ISlot<string> Content { get; set; }
  13. public void Compose(IContainer container)
  14. {
  15. container
  16. .Column(column =>
  17. {
  18. column.Item().Slot(Header);
  19. foreach (var i in Enumerable.Range(1, 10))
  20. column.Item().Slot(Content, i.ToString());
  21. });
  22. }
  23. }
  24. public class ComponentExamples
  25. {
  26. [Test]
  27. public void ComplexLayout()
  28. {
  29. RenderingTest
  30. .Create()
  31. .PageSize(PageSizes.A4)
  32. .ProducePdf()
  33. .ShowResults()
  34. .Render(content =>
  35. {
  36. content
  37. .Padding(10)
  38. .Border(1)
  39. .BorderColor(Colors.Grey.Medium)
  40. .Component<MyComponent>(component =>
  41. {
  42. component
  43. .Slot(x => x.Header)
  44. .Text("This is my text");
  45. component.Slot(x => x.Content, (input, container) =>
  46. {
  47. container
  48. .Background(Placeholders.BackgroundColor())
  49. .Padding(5)
  50. .Text(input);
  51. });
  52. });
  53. });
  54. }
  55. }
  56. }