You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Profiler.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using AutoMapper;
  2. using PuppeteerSharp;
  3. using BlackRock.Reporting.API.Core.Models;
  4. namespace BlackRock.Reporting.API.Profiles
  5. {
  6. public class Profiler : Profile
  7. {
  8. public Profiler()
  9. {
  10. CreateMap<OptionsForPdf, PdfOptions>().ConvertUsing<OptionsForPdfConverter>();
  11. }
  12. }
  13. public class OptionsForPdfConverter : ITypeConverter<OptionsForPdf, PdfOptions>
  14. {
  15. public PdfOptions Convert(OptionsForPdf source, PdfOptions destination, ResolutionContext context)
  16. {
  17. if (source == null)
  18. {
  19. return null;
  20. }
  21. destination = new PdfOptions()
  22. {
  23. DisplayHeaderFooter = source.DisplayHeaderFooter,
  24. HeaderTemplate = source.HeaderTemplate,
  25. Height = source.Height,
  26. Landscape = source.Landscape,
  27. OmitBackground = source.OmitBackground,
  28. PageRanges = source.PageRanges,
  29. PreferCSSPageSize = source.PreferCSSPageSize,
  30. PrintBackground = source.PrintBackground,
  31. Scale = source.Scale,
  32. Width = source.Width
  33. };
  34. destination.MarginOptions = new PuppeteerSharp.Media.MarginOptions()
  35. {
  36. Bottom = source.MarginBottom,
  37. Top = source.MarginTop,
  38. Right = source.MarginRight,
  39. Left = source.MarginLeft
  40. };
  41. switch (source.PaperFormatType)
  42. {
  43. case PaperFormatType.A4:
  44. destination.Format = PuppeteerSharp.Media.PaperFormat.A4;
  45. break;
  46. case PaperFormatType.A3:
  47. destination.Format = PuppeteerSharp.Media.PaperFormat.A3;
  48. break;
  49. case PaperFormatType.Letter:
  50. destination.Format = PuppeteerSharp.Media.PaperFormat.Letter;
  51. break;
  52. }
  53. return destination;
  54. }
  55. }
  56. }