using AutoMapper; using PuppeteerSharp; using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Mediator.UserMediator.Model; using BlackRock.Reporting.API.Mediator.UserMediator.Dto; namespace BlackRock.Reporting.API.Mediator.Mapping.DTOToEntity { public class PDFMapping : Profile { public PDFMapping() { CreateMap().ConvertUsing(); } } public class OptionsForPdfConverter : ITypeConverter { public PdfOptions Convert(OptionsForPdf source, PdfOptions destination, ResolutionContext context) { if (source == null) return destination; if (destination == null) destination = new PdfOptions(); destination.DisplayHeaderFooter = source.DisplayHeaderFooter; destination.HeaderTemplate = source.HeaderTemplate; destination.Height = source.Height; destination.Landscape = source.Landscape; destination.OmitBackground = source.OmitBackground; destination.PageRanges = source.PageRanges; destination.PreferCSSPageSize = source.PreferCSSPageSize; destination.PrintBackground = source.PrintBackground; destination.Scale = source.Scale; destination.Width = source.Width; destination.MarginOptions = new PuppeteerSharp.Media.MarginOptions() { Bottom = source.MarginBottom, Top = source.MarginTop, Right = source.MarginRight, Left = source.MarginLeft }; switch (source.PaperFormatType) { case PaperFormatType.A4: destination.Format = PuppeteerSharp.Media.PaperFormat.A4; break; case PaperFormatType.A3: destination.Format = PuppeteerSharp.Media.PaperFormat.A3; break; case PaperFormatType.Letter: destination.Format = PuppeteerSharp.Media.PaperFormat.Letter; break; } return destination; } } }