예제 #1
0
        public void DrawPage(object o, DrawPageArgs args)
        {
            var         g      = args.Context.CairoContext;
            RenderCairo render = new RenderCairo(g);

            render.RunPage(Pages[args.PageNr]);
        }
        private static void Print(string printer, UserPrintSettings userPrintSettings, Pages pages, bool isWindowsOs)
        {
            void HandlePrintBeginPrint(object o, BeginPrintArgs args)
            {
                var printing = (PrintOperation)o;

                printing.NPages = pages.Count;
            }

            void HandlePrintDrawPage(object o, DrawPageArgs args)
            {
                using (Cairo.Context g = args.Context.CairoContext)
                {
                    var render = new RenderCairo(g);
                    render.RunPage(pages[args.PageNr]);
                }
            }

            PrintOperation       printOperation = null;
            PrintOperationResult result;

            try
            {
                printOperation               = new PrintOperation();
                printOperation.Unit          = Unit.Points;
                printOperation.UseFullPage   = true;
                printOperation.AllowAsync    = true;
                printOperation.PrintSettings = new PrintSettings
                {
                    Printer     = printer,
                    Orientation = (PageOrientation)Enum.Parse(typeof(PageOrientation), userPrintSettings.PageOrientation.ToString()),
                    NCopies     = (int)userPrintSettings.NumberOfCopies
                };

                printOperation.BeginPrint += HandlePrintBeginPrint;
                printOperation.DrawPage   += HandlePrintDrawPage;

                result = printOperation.Run(PrintOperationAction.Print, null);
            }
            catch (Exception e) when(e.Message == "Error from StartDoc")
            {
                result = PrintOperationResult.Cancel;
                _logger.Debug("Операция печати отменена");
            }
            finally
            {
                if (printOperation != null)
                {
                    printOperation.BeginPrint -= HandlePrintBeginPrint;
                    printOperation.DrawPage   -= HandlePrintDrawPage;
                    printOperation.Dispose();
                }
            }

            if (isWindowsOs && new[] { PrintOperationResult.Apply, PrintOperationResult.InProgress }.Contains(result))
            {
                ShowPrinterQueue(printer);
            }
        }
예제 #3
0
 private void HandlePrintDrawPage(object o, DrawPageArgs args)
 {
     using (var context = args.Context.CairoContext)
     {
         var render = new RenderCairo(context);
         render.RunPage(_pages[args.PageNr]);
     }
 }
예제 #4
0
        public void DrawPage(object o, DrawPageArgs args)
        {
            var g = args.Context.CairoContext;
            int pageNumber, reportNumber;

            CalculateDocPage(args.PageNr, out reportNumber, out pageNumber);

            RenderCairo render = new RenderCairo(g);

            render.RunPage(reportPages[reportNumber][pageNumber]);
        }