public static PrinterInfo GetPrinterInfo(object printerName) // We want to read just once to avoid double access of printerSettings which can be slow in case of non-local printer { //SetDefaultPrinter(printerName); var printerSettings = new PrinterSettings(); printerSettings.PrinterName = printerName.ToString(); PrinterInfo printerInfo = new PrinterInfo(); printerInfo.PrinterName = printerName.ToString(); printerInfo.Collate = printerSettings.Collate; printerInfo.Color = printerSettings.DefaultPageSettings.Color; printerInfo.Copies = printerSettings.Copies; printerInfo.Duplex = printerSettings.Duplex; printerInfo.Landscape = printerSettings.DefaultPageSettings.Landscape; printerInfo.PaperSize = printerSettings.DefaultPageSettings.PaperSize.ToString(); foreach (PaperSize paperSize in printerSettings.PaperSizes) { printerInfo.PaperSizes.Add(paperSize.ToString()); } printerInfo.PaperSource = printerSettings.DefaultPageSettings.PaperSource.ToString(); foreach (PaperSource paperSource in printerSettings.PaperSources) { printerInfo.PaperSources.Add(paperSource.ToString()); } printerInfo.PrinterResolution = printerSettings.DefaultPageSettings.PrinterResolution.ToString(); foreach (PrinterResolution printerResolution in printerSettings.PrinterResolutions) { printerInfo.PrinterResolutions.Add(printerResolution.ToString()); } return(printerInfo); }
private void FillPrinterDefaults(PrinterInfo printerInfo, bool isAdobe) { if (isAdobe) { cbCollateAdobe.Checked = printerInfo.Collate; numCopiesAdobe.Value = printerInfo.Copies; rbDuplexSimplexAdobe.Checked = printerInfo.Duplex == Duplex.Simplex; rbDuplexHorizontalAdobe.Checked = printerInfo.Duplex == Duplex.Horizontal; rbDuplexVerticalAdobe.Checked = printerInfo.Duplex == Duplex.Vertical; rbLandscapeAdobe.Checked = printerInfo.Landscape; rbPortraitAdobe.Checked = !printerInfo.Landscape; cbPrintInColorAdobe.Checked = printerInfo.Color; } else { cbCollate.Checked = printerInfo.Collate; numCopies.Value = printerInfo.Copies; rbDuplexSimplex.Checked = printerInfo.Duplex == Duplex.Simplex; rbDuplexHorizontal.Checked = printerInfo.Duplex == Duplex.Horizontal; rbDuplexVertical.Checked = printerInfo.Duplex == Duplex.Vertical; rbLandscape.Checked = printerInfo.Landscape; rbPortrait.Checked = !printerInfo.Landscape; cbPrintInColor.Checked = printerInfo.Color; } PdfPrintTest.FillComboBox(isAdobe ? cmbxPrinterResolutionsAdobe : cmbxPrinterResolutions, printerInfo.PrinterResolutions, printerInfo.PrinterResolution); PdfPrintTest.FillComboBox(isAdobe ? cmbxPaperSizeAdobe : cmbxPaperSize, printerInfo.PaperSizes, printerInfo.PaperSize); PdfPrintTest.FillComboBox(isAdobe ? cmbxPaperSourceAdobe : cmbxPaperSource, printerInfo.PaperSources, printerInfo.PaperSource); }