ImageTemplate.cs 840 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using QuestPDF.Fluent;
  3. using QuestPDF.Helpers;
  4. using QuestPDF.Infrastructure;
  5. namespace QuestPDF.ReportSample.Layouts
  6. {
  7. public class ImageTemplate : IComponent
  8. {
  9. private Func<Size, byte[]> Source { get; }
  10. private float AspectRatio { get; }
  11. public ImageTemplate(byte[] source, float aspectRatio = 1.333333f) : this(_ => source, aspectRatio)
  12. {
  13. }
  14. public ImageTemplate(Func<Size, byte[]> source, float aspectRatio = 1.333333f)
  15. {
  16. Source = source;
  17. AspectRatio = aspectRatio;
  18. }
  19. public void Compose(IContainer container)
  20. {
  21. container
  22. .AspectRatio(AspectRatio)
  23. .Background(Colors.Grey.Lighten3)
  24. .Image(Source(Size.Zero));
  25. }
  26. }
  27. }