Ejemplo n.º 1
0
                public DemoPrinting ()
                {
			print = new PrintOperation ();
			
			print.BeginPrint += new BeginPrintHandler (OnBeginPrint);
			print.DrawPage += new DrawPageHandler (OnDrawPage);
			print.EndPrint += new EndPrintHandler (OnEndPrint);

			print.Run (PrintOperationAction.PrintDialog, null);
		}
Ejemplo n.º 2
0
        private void PrintDoc(SelectablePrintDocument doc, PageOrientation orientation, int copies)
        {
            if (doc == null)
            {
                return;
            }

            switch (doc.Document.PrintType)
            {
            case PrinterType.RDL:
                var reportInfo = (doc.Document as IPrintableRDLDocument).GetReportInfo();

                var action = showDialog ? PrintOperationAction.PrintDialog : PrintOperationAction.Print;
                showDialog = false;

                Printer             = new PrintOperation();
                Printer.Unit        = Unit.Points;
                Printer.UseFullPage = true;

                Printer.PrintSettings = PrintSettings ?? new PrintSettings();

                Printer.PrintSettings.Orientation = orientation;

                var rprint = new ReportPrinter(reportInfo);
                rprint.PrepareReport();

                Printer.NPages = rprint.PageCount;
                Printer.PrintSettings.NCopies = copies;
                if (copies > 1)
                {
                    Printer.PrintSettings.Collate = true;
                }

                Printer.DrawPage += rprint.DrawPage;
                Printer.Run(action, null);

                PrintSettings = Printer.PrintSettings;
                break;

            case PrinterType.ODT:
            case PrinterType.None:
            default:
                break;
            }
        }
Ejemplo n.º 3
0
		void HandleActivated (object sender, EventArgs e)
		{
			// Commit any pending changes.
			PintaCore.Tools.Commit ();

			var op = new PrintOperation ();
			op.BeginPrint += HandleBeginPrint;
			op.DrawPage += HandleDrawPage;

			var result = op.Run (PrintOperationAction.PrintDialog, PintaCore.Chrome.MainWindow);

			if (result == PrintOperationResult.Apply) {
				// TODO - save print settings.
			} else if (result == PrintOperationResult.Error) {
				// TODO - show a proper dialog.
				System.Console.WriteLine ("Printing error");
			}
		}
Ejemplo n.º 4
0
        public static void Main(string[] Pages)
        {
            Application.Init();
            var print = new Gtk.PrintOperation();

            print.PrintSettings            = new Gtk.PrintSettings();
            print.PrintSettings.Scale      = 33.75;
            print.PrintSettings.Resolution = 1200;
            print.JobName     = "FeuerwehrCloud Ausdruck";
            print.BeginPrint += (obj2, args) => { print.NPages = Pages.Length; };
            print.DrawPage   += (obj2, args) => {
                try {
                    FeuerwehrCloud.Helper.Logger.WriteLine("|  > [ImagePrinter] *** Page " + args.PageNr.ToString() + " of " + Pages.Length.ToString());
                    var imageBit = default(byte[]);
                    var image    = System.Drawing.Image.FromFile("/tmp/" + Pages[args.PageNr]);
                    using (var memoryStream = new MemoryStream()) {
                        image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
                        imageBit = memoryStream.ToArray();
                    }
                    Gtk.PrintContext context = args.Context;
                    try {
                        var pixBuf = new Gdk.Pixbuf(imageBit, image.Width, image.Height);
                        try {
                            Cairo.Context cr = context.CairoContext;
                            cr.MoveTo(0, 0);
                            Gdk.CairoHelper.SetSourcePixbuf(cr, pixBuf, 0, 10);
                            cr.Paint();
                            ((IDisposable)cr).Dispose();
                        } catch (Exception ex4) {
                            FeuerwehrCloud.Helper.Logger.WriteLine("|||  > [ImagePrinter] *** ERROR: " + ex4.ToString());
                        }
                    } catch (Exception ex5) {
                        FeuerwehrCloud.Helper.Logger.WriteLine("|||  > [ImagePrinter] *** ERROR: " + ex5.ToString());
                    }
                } catch (Exception ex3) {
                    FeuerwehrCloud.Helper.Logger.WriteLine("||| > [ImagePrinter] *** ERROR: " + ex3.ToString());
                }
            };
            print.EndPrint += (obj2, args) => { FeuerwehrCloud.Helper.Logger.WriteLine("|  > [ImagePrinter] *** Printing finished "); Application.Quit(); };
            print.Run(Gtk.PrintOperationAction.Print, null);
        }
Ejemplo n.º 5
0
        private void PrintDoc(RouteList route, RouteListPrintableDocuments type, PageOrientation orientation, int copies)
        {
            var reportInfo = PrintRouteListHelper.GetRDL(route, type, uow);

            var action = showDialog ? PrintOperationAction.PrintDialog : PrintOperationAction.Print;

            showDialog = false;

            Printer             = new PrintOperation();
            Printer.Unit        = Unit.Points;
            Printer.UseFullPage = true;
            //Printer.DefaultPageSetup = new PageSetup();

            if (PrintSettings == null)
            {
                Printer.PrintSettings = new PrintSettings();
            }
            else
            {
                Printer.PrintSettings = PrintSettings;
            }

            Printer.PrintSettings.Orientation = orientation;

            var rprint = new ReportPrinter(reportInfo);

            rprint.PrepareReport();

            Printer.NPages = rprint.PageCount;
            Printer.PrintSettings.NCopies = copies;
            if (copies > 1)
            {
                Printer.PrintSettings.Collate = true;
            }

            Printer.DrawPage += rprint.DrawPage;
            Printer.Run(action, null);

            PrintSettings = Printer.PrintSettings;
        }
Ejemplo n.º 6
0
        protected virtual void OnPrintActionActivated(object sender, System.EventArgs e)
        {
            using (PrintContext context = new PrintContext(GdkWindow.Handle))
            {

                printing = new PrintOperation();
                printing.Unit = Unit.Points;
                printing.UseFullPage = false;

                printing.BeginPrint += HandlePrintBeginPrint;
                printing.DrawPage += HandlePrintDrawPage;
                printing.EndPrint += HandlePrintEndPrint;

                printing.Run(PrintOperationAction.PrintDialog, null);
            }
        }
Ejemplo n.º 7
0
 void miPrint_ButtonPressEvent(object o, ButtonPressEventArgs args)
 {
     PrintOperation po = new PrintOperation();
     po.BeginPrint += delegate(object o2, BeginPrintArgs args2)
     {
         po.NPages = 1;
     };
     po.DrawPage += delegate(object o2, DrawPageArgs args2)
     {
         GTKGraphics dg = new GTKGraphics(CairoHelper.GetContext(args2.Context));
         DPrintViewer dvPrint = new DPrintViewer();
         dvPrint.SetPageSize(de.PageSize);
         GTKPrintSettings dps =
             new GTKPrintSettings(args2.Context.DpiX, args2.Context.DpiY, args2.Context.PageSetup);
         dvPrint.Paint(dg, dps, de.BackgroundFigure, de.Figures);
     };
     po.Run(PrintOperationAction.PrintDialog, this);
 }
Ejemplo n.º 8
0
		private void OnPrint(object sender, EventArgs arguments){	
			PrintOperation printing = new PrintOperation();
			
			List<LabelRenderer> labels = new List<LabelRenderer>();
			foreach(Model.Item item in Inventory.Items){
				Product p = item as Product;
				if(p != null && p.LabelMethod == LabelMethod.Print){
					labels.Add(new LabelRenderer(item,Inventory.Settings.LabelLayout));
				}
			}
			
			int labelsPerPage = Inventory.Settings.PageLayout.LabelsPerPage;
			int currentLabel = 0;
			
			printing.BeginPrint += delegate (object obj, Gtk.BeginPrintArgs args)
			{
				printing.NPages = (int)Math.Ceiling( (double)labels.Count/(labelsPerPage));
				printing.Unit = Unit.Mm;
			};
			
            printing.DrawPage += delegate (object obj, Gtk.DrawPageArgs args)
			{
				PrintContext context = args.Context;
				
				using(Context cr = context.CairoContext){
					// scale down the cairo context
					
					// //context.DpiY,
					
					Pango.Layout layout = context.CreatePangoLayout();
					ArrayList pageLabels = new ArrayList();
					// it is impossible that we have 0 items, otherwise the page would be empty
					do {
						pageLabels.Add(labels[currentLabel]);
						++currentLabel;
					}
					while (currentLabel%labelsPerPage != 0 && currentLabel < labels.Count-1);
					
					PageRenderer page = new PageRenderer(pageLabels,Inventory.Settings.PageLayout);
					page.Render(cr,layout,0,0,context.Width,context.Height);
				}
			};
			
			printing.Run (PrintOperationAction.PrintDialog, (Gtk.Window)this.Toplevel);
		}
Ejemplo n.º 9
0
        public static void PrintAll(IEnumerable<IPrintableDocument> documents)
        {
            if(Environment.OSVersion.Platform != PlatformID.MacOSX && Environment.OSVersion.Platform != PlatformID.Unix)
            {
                PrintAll_Win_Workaround(documents);
                return;
            }

            PrintOperation printOp;
            printOp = new PrintOperation();
            printOp.Unit = Unit.Points;
            printOp.UseFullPage = true;
            printOp.ShowProgress = true;
            var documentsRDL = documents.Where(doc=>doc.PrintType==PrinterType.RDL).ToList();
            BatchRDLRenderer renderer = new BatchRDLRenderer(documentsRDL);

            var result = LongOperationDlg.StartOperation(
                renderer.PrepareDocuments,
                "Подготовка к печати...",
                documentsRDL.Count()
            );
            if (result == LongOperationResult.Canceled)
                return;

            printOp.NPages = renderer.PageCount;
            if (documentsRDL.Any(x => x.Orientation == DocumentOrientation.Landscape))
            {
                printOp.RequestPageSetup += renderer.RequestPageSetup;
            }

            printOp.DrawPage += renderer.DrawPage;
            printOp.Run(PrintOperationAction.PrintDialog, null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Альтернативная релализация печати, специально для обхода бага в кайро при поворачивании(со старой реализацией печати пол Linux)
        /// https://bugzilla.mozilla.org/show_bug.cgi?id=1205854#c16
        /// В новой при установке ориентации для каждой странице на большенстве принтеров обрезается часть выходящая за поворот. Хотя ориентация правильная.
        /// На некоторых принтерах например в водовозе, табличка рисуется за вертикалью листа а текст нет.
        /// используется только на винде, в линуксе такой проблемы нет.
        /// </summary>
        private static void PrintAll_Win_Workaround(IEnumerable<IPrintableDocument> documents)
        {
            PrintOperation printOp;
            var documentsRDL_Portrait = documents.Where(doc => doc.PrintType==PrinterType.RDL && doc.Orientation == DocumentOrientation.Portrait).ToList();
            var documentsRDL_Landscape = documents.Where(doc=>doc.PrintType==PrinterType.RDL && doc.Orientation == DocumentOrientation.Landscape).ToList();

            if (documentsRDL_Portrait.Count > 0)
            {
                printOp = new PrintOperation();
                printOp.Unit = Unit.Points;
                printOp.UseFullPage = true;
                printOp.ShowProgress = true;
                printOp.DefaultPageSetup = new PageSetup();
                printOp.DefaultPageSetup.Orientation = PageOrientation.Portrait;

                BatchRDLRenderer renderer = new BatchRDLRenderer(documentsRDL_Portrait);

                var result = LongOperationDlg.StartOperation(
                                renderer.PrepareDocuments,
                                "Подготовка к печати портретных страниц...",
                                documentsRDL_Portrait.Count()
                            );
                if (result == LongOperationResult.Canceled)
                    return;

                printOp.NPages = renderer.PageCount;

                printOp.DrawPage += renderer.DrawPage;
                printOp.Run(PrintOperationAction.PrintDialog, null);
            }

            if(documentsRDL_Landscape.Count > 0)
            {
                printOp = new PrintOperation();
                printOp.Unit = Unit.Points;
                printOp.UseFullPage = true;
                printOp.ShowProgress = true;
                printOp.DefaultPageSetup = new PageSetup();
                printOp.DefaultPageSetup.Orientation = PageOrientation.Landscape;

                BatchRDLRenderer renderer = new BatchRDLRenderer(documentsRDL_Landscape);

                var result = LongOperationDlg.StartOperation(
                    renderer.PrepareDocuments,
                    "Подготовка к печати альбомных страниц...",
                    documentsRDL_Landscape.Count()
                );
                if (result == LongOperationResult.Canceled)
                    return;

                printOp.NPages = renderer.PageCount;

                printOp.DrawPage += renderer.DrawPage;
                printOp.Run(PrintOperationAction.PrintDialog, null);
            }
        }
Ejemplo n.º 11
0
        protected void OnPrintActionActivated(object sender, System.EventArgs e)
        {
            using (PrintContext context = new PrintContext(GdkWindow.Handle))
            {
                printing = new PrintOperation();
                printing.Unit = Unit.Points;
                printing.UseFullPage = true;
                printing.DefaultPageSetup = new PageSetup();
                printing.DefaultPageSetup.Orientation =
                    report.PageHeightPoints > report.PageWidthPoints ? PageOrientation.Portrait : PageOrientation.Landscape;

                printing.BeginPrint += HandlePrintBeginPrint;
                printing.DrawPage += HandlePrintDrawPage;
                printing.EndPrint += HandlePrintEndPrint;

                printing.Run(PrintOperationAction.PrintDialog, null);
            }
        }