| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using AutoMapper;
- using PuppeteerSharp;
- using BlackRock.Reporting.API.Core.Models;
-
- namespace BlackRock.Reporting.API.Profiles
- {
-
- public class Profiler : Profile
- {
- public Profiler()
- {
- CreateMap<OptionsForPdf, PdfOptions>().ConvertUsing<OptionsForPdfConverter>();
- }
- }
-
- public class OptionsForPdfConverter : ITypeConverter<OptionsForPdf, PdfOptions>
- {
- 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;
- }
- }
- }
|