コード例 #1
0
        public override void OnStartPrint(PrintDocument document, PrintEventArgs e)
        {
            var printSettings = new PMPrintSettings();

            printSettings.Collate = document.PrinterSettings.Collate;
            switch (document.PrinterSettings.Duplex)
            {
            case Duplex.Simplex: printSettings.DuplexMode = PMDuplexMode.None; break;

            case Duplex.Vertical: printSettings.DuplexMode = PMDuplexMode.Tumble; break;

            case Duplex.Horizontal: printSettings.DuplexMode = PMDuplexMode.NoTumble; break;
            }
            printSettings.SetPageRange((uint)document.PrinterSettings.MinimumPage, (uint)document.PrinterSettings.MaximumPage);
            printSettings.FirstPage = (uint)document.PrinterSettings.FromPage;
            printSettings.LastPage  = (uint)document.PrinterSettings.ToPage;
            if (document.DocumentName != null)
            {
                using (var jobName = new CFString(document.DocumentName))
                    PMPrintSettingsSetJobName(printSettings.Handle, jobName.Handle);
            }
            var printInfo = document.DefaultPageSettings.print_info;

            printInfo.Printer = NSPrinter.PrinterWithName(document.PrinterSettings.PrinterName);

            sessionHandle = printInfo.GetPMPrintSession();
            var result = PMSessionBeginCGDocumentNoDialog(sessionHandle, printSettings.Handle, printInfo.GetPMPageFormat());
        }
コード例 #2
0
        internal static NSPrinter PrinterWithNameOrDefaultPrinter(string printerName)
        {
            NSPrinter printer = null;

            if (!string.IsNullOrEmpty(printerName))
            {
                try { printer = NSPrinter.PrinterWithName(printerName); } catch { }
            }
            return(printer ?? new NSPrinter());
        }