We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Passing information from (Aspose)PageSetup to (System)PrinterSettings

Dear Aspose,


I am using Aspose.Cells for .NET to implement my project
as I am using the print dialog from microsoft for users to choose their desire print settings.

I would like to pass the defined/modified page setup from the worksheet/workbook into the print dialog, then pass the printerSettings back into WorkbookRender to print the document.

In short
Aspose.Cells.PageSetup -> System.Drawing.Printing.PrinterSettings.

Is there a quick way of cloning the settings between the two class?
or should I map the settings manually as below?

Many Thanks,

---------------------- Code ----------------------
private PrinterSettings SetPrinterSettings(PrinterSettings printerSettings, PageSetup pageSetup)
{
// Set LandScape
if (pageSetup.Orientation == PageOrientationType.Landscape)
printerSettings.DefaultPageSettings.Landscape = true;

// Set colour
printerSettings.DefaultPageSettings.Color = pageSetup.BlackAndWhite;

// Set Margin
printerSettings.DefaultPageSettings.Margins.Bottom = (int)pageSetup.BottomMarginInch * 100;
printerSettings.DefaultPageSettings.Margins.Top = (int)pageSetup.TopMarginInch * 100;
printerSettings.DefaultPageSettings.Margins.Left = (int)pageSetup.LeftMarginInch * 100;
printerSettings.DefaultPageSettings.Margins.Right = (int)pageSetup.RightMarginInch * 100;

// Set PaperSize
string paperName = Enum.GetName(typeof(PaperKind), (int)pageSetup.PaperSize);
printerSettings.DefaultPageSettings.PaperSize = this.GetPaperSizeWithName(paperName);
return printerSettings;
}

private System.Drawing.Printing.PaperSize GetPaperSizeWithName(string paperName)
{
// Set default paper size
PrinterSettings settings = new PrinterSettings();

foreach (System.Drawing.Printing.PaperSize pSize in settings.PaperSizes)
{
if (pSize.PaperName == paperName)
return pSize;
}

return settings.DefaultPageSettings.PaperSize;
}

---------------------- Code ----------------------

Hi,


Thanks for your posting and using Aspose.Cells.

You will have to manually convert PrinterSettings > PageSetup and PageSetup > PrinterSettings > PageSetup. It is one time effort so you can write some utility or conversion methods like this

C#
PageSetup pageSetup = Convert.ToPageSetup(printerSettings);
printerSettings = Convert.ToPrinterSettings(pageSetup);