+ IntPtr ppd_handle = OpenPrinter (printer);
+ if (ppd_handle == IntPtr.Zero)
+ return;
+
+ LoadPrinterResolutionsAndDefault (printer, settings, ppd_handle);
+
+ ClosePrinter (ref ppd_handle);
+ }
+
+ /// <summary>
+ /// Create a PrinterResolution from a string Resolution that is set in the PPD option.
+ /// An example of Resolution is "600x600dpi" or "600dpi". Returns null if malformed or "Unknown".
+ /// </summary>
+ private PrinterResolution ParseResolution (string resolution)
+ {
+ if (String.IsNullOrEmpty (resolution))
+ return null;
+
+ int dpiIndex = resolution.IndexOf ("dpi");
+ if (dpiIndex == -1)
+ {
+ // Resolution is "Unknown" or unparsable
+ return null;
+ }
+ resolution = resolution.Substring (0, dpiIndex);
+
+ int x_resolution, y_resolution;
+ try {
+ if (resolution.Contains ("x")) {
+ string[] resolutions = resolution.Split (new[] {'x'});
+ x_resolution = Convert.ToInt32 (resolutions [0]);
+ y_resolution = Convert.ToInt32 (resolutions [1]);
+ } else {
+ x_resolution = Convert.ToInt32 (resolution);
+ y_resolution = x_resolution;
+ }
+ } catch (Exception) {
+ return null;
+ }
+
+ return new PrinterResolution (x_resolution, y_resolution, PrinterResolutionKind.Custom);