Пример #1
0
        private void Print(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                PrintDialog dlg = new PrintDialog();
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf    = new PrintPluginViewModel(configData);
                var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(item.FileName));

                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                System.Printing.PrintCapabilities capabilities = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket);
                var PageWidth  = (int)capabilities.PageImageableArea.ExtentWidth;
                var PageHeight = (int)capabilities.PageImageableArea.ExtentHeight;

                var panel = new StackPanel
                {
                    Margin = new Thickness(conf.Margin),
                };

                var image = new Image
                {
                    Source  = BitmapLoader.Instance.LoadImage(outfile, PageWidth > PageHeight ? PageWidth : PageHeight, conf.Rotate ? 90 : 0),
                    Width   = PageWidth,
                    Height  = PageHeight,
                    Stretch = Stretch.Uniform,
                };


                panel.Children.Add(image);
                panel.UpdateLayout();
                panel.Measure(new Size(PageWidth, PageHeight));
                panel.Arrange(new Rect(new Point(0, 0), panel.DesiredSize));
                panel.UpdateLayout();
                dlg.PrintVisual(panel, item.Name);
                image.Source = null;
                panel.Children.Clear();
                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error print file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }

            configData.IsRedy = true;
        }
Пример #2
-1
        private void Print(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                PrintDialog dlg = new PrintDialog();
                configData.IsRedy = false;
                configData.IsError = false;
                var conf = new PrintPluginViewModel(configData);
                var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(item.FileName));

                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                System.Printing.PrintCapabilities capabilities = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket);
                var PageWidth = (int)capabilities.PageImageableArea.ExtentWidth;
                var PageHeight = (int)capabilities.PageImageableArea.ExtentHeight;

                var panel = new StackPanel
                {
                    Margin = new Thickness(conf.Margin),
                };

                var image = new Image
                {
                    Source = BitmapLoader.Instance.LoadImage(outfile, PageWidth > PageHeight ? PageWidth : PageHeight, conf.Rotate ? 90 : 0),
                    Width = PageWidth ,
                    Height = PageHeight,
                    Stretch = Stretch.Uniform,
                };

               
                panel.Children.Add(image);
                panel.UpdateLayout();
                panel.Measure(new Size(PageWidth, PageHeight));
                panel.Arrange(new Rect(new Point(0, 0), panel.DesiredSize));
                panel.UpdateLayout();
                dlg.PrintVisual(panel, item.Name);
                image.Source = null;
                panel.Children.Clear();
                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error print file", exception);
                configData.IsError = true;
                configData.Error = exception.Message;
            }

            configData.IsRedy = true;            
        }