ImageTemplate.cs 805 B

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