Beispiel #1
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            if (!ScanningAndPrinting.CanPrint)
            {
                Utility.ShowWiaError(documentWorkspace);
                return(null);
            }

            using (new PushNullToolMode(documentWorkspace))
            {
                // render image to a bitmap, save it to disk
                Surface scratch = documentWorkspace.BorrowScratchSurface(this.GetType().Name + ".PerformAction()");

                try
                {
                    scratch.Clear();
                    RenderArgs ra = new RenderArgs(scratch);

                    documentWorkspace.Update();

                    using (new WaitCursorChanger(documentWorkspace))
                    {
                        ra.Surface.Clear(ColorBgra.White);
                        documentWorkspace.Document.Render(ra, false);
                    }

                    string tempName = Path.GetTempFileName() + ".bmp";
                    ra.Bitmap.Save(tempName, ImageFormat.Bmp);

                    try
                    {
                        ScanningAndPrinting.Print(documentWorkspace, tempName);
                    }

                    catch (Exception ex)
                    {
                        Utility.ShowWiaError(documentWorkspace);
                        Tracing.Ping(ex.ToString());
                        // TODO: do a "better" error dialog here
                    }

                    // Try to delete the temp file but don't worry if we can't
                    bool result = FileSystem.TryDeleteFile(tempName);
                }

                finally
                {
                    documentWorkspace.ReturnScratchSurface(scratch);
                }
            }

            return(null);
        }
Beispiel #2
0
 public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
 {
     if (!ScanningAndPrinting.CanPrint)
     {
         ShowWiaError(documentWorkspace);
         return(null);
     }
     using (new PushNullToolMode(documentWorkspace))
     {
         Surface surface = documentWorkspace.BorrowScratchSurface(base.GetType().Name + ".PerformAction()");
         try
         {
             surface.Clear();
             RenderArgs args = new RenderArgs(surface);
             documentWorkspace.QueueUpdate();
             using (new WaitCursorChanger(documentWorkspace))
             {
                 args.Surface.Clear(ColorBgra.White);
                 documentWorkspace.Document.Render(args, false);
             }
             string filename = Path.GetTempFileName() + ".bmp";
             args.Bitmap.Save(filename, ImageFormat.Bmp);
             try
             {
                 ScanningAndPrinting.Print(documentWorkspace, filename);
             }
             catch (Exception)
             {
                 ShowWiaError(documentWorkspace);
             }
             bool flag = FileSystem.TryDeleteFile(filename);
         }
         catch (Exception exception)
         {
             ExceptionDialog.ShowErrorDialog(documentWorkspace, exception);
         }
         finally
         {
             documentWorkspace.ReturnScratchSurface(surface);
         }
     }
     return(null);
 }