/// <summary> /// Converts this data to a .NET PageSettings class. /// </summary> public static PageSettings ToPageSettings(this PageSettingsData source) { // Validate if (source == null) { throw new ArgumentNullException(nameof(source)); } // Create system printer settings var target = new PageSettings { Color = source.Color, Landscape = source.Landscape, Margins = source.Margins.ToMargins(), }; // Find and set paper size when available in system printer settings var printer = new PrinterSettings { PrinterName = source.PrinterName }; foreach (PaperSize paperSize in printer.PaperSizes) { if (paperSize.PaperName == source.PaperName) { target.PaperSize = paperSize; } } // Return complete settings return(target); }
/// <summary> /// Creates a data structure of this type from .NET PageSettings. /// </summary> public static PageSettingsData ToData(this PageSettings source) { // Validate if (source == null) { throw new ArgumentNullException(nameof(source)); } // Convert... var target = new PageSettingsData { Color = source.Color, Landscape = source.Landscape, Margins = source.Margins.ToData(), PaperWidth = source.PaperSize.Width, PaperHeight = source.PaperSize.Height, PaperName = source.PaperSize.PaperName, PaperSizeKind = (int)source.PaperSize.Kind, PrinterName = source.PrinterSettings.PrinterName }; return(target); }