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.

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