示例#1
0
        public void TakeTheChart()
        {
            var viewbox = new Viewbox();

            viewbox.Child = chart;
            viewbox.Measure(chart.RenderSize);
            viewbox.Arrange(new Rect(new Point(0, 0), chart.RenderSize));
            chart.Update(true, true);
            viewbox.UpdateLayout();
            SaveToPng(chart, chart.Tag.ToString());
        }
        private double GethDocumentHeight(Viewbox viewbox, CommentRichTextBox RichTextBox)
        {
            viewbox.Child = RichTextBox;
            viewbox.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            viewbox.Arrange(new Rect(viewbox.DesiredSize));
            var size = new Size()
            {
                Height = viewbox.ActualHeight, Width = viewbox.ActualWidth
            };

            return(size.Height);
        }
示例#3
0
        private static void GenerateImage(Viewbox control, Stream result)
        {
            //Set background to white
            //control.Background = Brushes.White;

            Size controlSize = RetrieveDesiredSize(control);
            Rect rect        = new Rect(0, 0, controlSize.Width, controlSize.Height);

            RenderTargetBitmap rtb = new RenderTargetBitmap((int)controlSize.Width, (int)controlSize.Height, IMAGE_DPI, IMAGE_DPI, PixelFormats.Pbgra32);

            control.Arrange(rect);
            rtb.Render(control);

            PngBitmapEncoder png = new PngBitmapEncoder();

            png.Frames.Add(BitmapFrame.Create(rtb));
            png.Save(result);
        }
示例#4
0
        public System.Drawing.Bitmap ApplyShader(System.Drawing.Bitmap Source)
        {
            System.Drawing.Bitmap returnBitmap = null;

            try
            {
                returnBitmap = Source;

                img.BeginInit();
                img.Width  = Source.Width;
                img.Height = Source.Height;

                img.Source = BitmapToBitmapSource.ToBitmapSource(Source);;
                img.EndInit();

                viewbox.Measure(new Size(img.Width * scale, img.Height * scale));
                viewbox.Arrange(new Rect(0, 0, img.Width * scale, img.Height * scale));
                viewbox.UpdateLayout();

                MemoryStream outStream = new MemoryStream();

                RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.HighQuality);
                RenderTargetBitmap rtBitmap = new RenderTargetBitmap(Convert.ToInt32(img.Width * scale), Convert.ToInt32(img.Height * scale), Convert.ToInt32(WPF_DPI_X), Convert.ToInt32(WPF_DPI_Y), PixelFormats.Pbgra32);
                rtBitmap.Render(viewbox);


                BitmapFrame frame = BitmapFrame.Create(rtBitmap);
                encoder = new JpegBitmapEncoder();
                encoder.Frames.Add(frame);
                encoder.Save(outStream);
                returnBitmap = new System.Drawing.Bitmap(outStream);

                encoder  = null;
                rtBitmap = null;
                frame    = null;
            }
            catch (Exception ex)
            {
                returnBitmap = null;
            }

            return(returnBitmap);
        }
示例#5
0
        public static void Print(FrameworkElement Element)
        {
            var dlg = new PrintDialog();

            dlg.PrintTicket.PageOrientation = System.Printing.PageOrientation.Portrait;

            /*var result = dlg.ShowDialog();
             * if (result == null || !(bool)result)
             *  return;*/
            var page = new Viewbox {
                Child = Element
            };


            page.Measure(new Size(dlg.PrintableAreaWidth, dlg.PrintableAreaHeight));
            page.Arrange(new Rect(new Point(0, 0), page.DesiredSize));

            dlg.PrintVisual(page, "Печать визиток");
        }
示例#6
0
        private static void RenderToLMap(Image li, string file)
        {
            Viewbox viewbox = new Viewbox {
                Child = li
            };

            viewbox.Measure(new Size(li.Width, li.Height));
            viewbox.Arrange(new Rect(0, 0, li.Width, li.Height));
            viewbox.UpdateLayout();
            RenderTargetBitmap rtb = new RenderTargetBitmap((int)li.Width, (int)li.Height, 96, 96, PixelFormats.Pbgra32);

            rtb.Render(viewbox);
            PngBitmapEncoder enc = new PngBitmapEncoder();

            enc.Frames.Add(BitmapFrame.Create(rtb));
            using (FileStream stm = File.Create(file)) {
                enc.Save(stm);
            }
        }
        public void Viewbox_Stretch_Uniform_Child()
        {
            var target = new Viewbox()
            {
                Child = new Rectangle()
                {
                    Width = 100, Height = 50
                }
            };

            target.Measure(new Size(200, 200));
            target.Arrange(new Rect(new Point(0, 0), target.DesiredSize));

            Assert.Equal(new Size(200, 100), target.DesiredSize);
            var scaleTransform = target.Child.RenderTransform as ScaleTransform;

            Assert.NotNull(scaleTransform);
            Assert.Equal(2.0, scaleTransform.ScaleX);
            Assert.Equal(2.0, scaleTransform.ScaleY);
        }
        public void Viewbox_Stretch_Uniform_Child_With_Unrestricted_Width()
        {
            var target = new Viewbox()
            {
                Child = new Rectangle()
                {
                    Width = 100, Height = 50
                }
            };

            target.Measure(new Size(double.PositiveInfinity, 200));
            target.Arrange(new Rect(new Point(0, 0), target.DesiredSize));

            Assert.Equal(new Size(400, 200), target.DesiredSize);
            var scaleTransform = target.Child.RenderTransform as ScaleTransform;

            Assert.NotNull(scaleTransform);
            Assert.Equal(4.0, scaleTransform.ScaleX);
            Assert.Equal(4.0, scaleTransform.ScaleY);
        }
示例#9
0
        /// <summary>
        ///     Render the frameworkElement to a BitmapSource
        /// </summary>
        /// <param name="frameworkElement">FrameworkElement</param>
        /// <param name="size">Size, using the bound as size by default</param>
        /// <param name="dpiX">Horizontal DPI settings</param>
        /// <param name="dpiY">Vertical DPI settings</param>
        /// <returns>BitmapSource</returns>
        public static BitmapSource ToBitmapSource(this FrameworkElement frameworkElement, Size?size = null, double dpiX = 96.0, double dpiY = 96.0)
        {
            if (frameworkElement == null)
            {
                throw new ArgumentNullException(nameof(frameworkElement));
            }
            // Make sure we have a size
            if (!size.HasValue)
            {
                var bounds = VisualTreeHelper.GetDescendantBounds(frameworkElement);
                size = bounds != Rect.Empty ? bounds.Size : new Size(16, 16);
            }

            // Create a viewbox to render the frameworkElement in the correct size
            var viewbox = new Viewbox
            {
                //frameworkElement to render
                Child = frameworkElement
            };

            viewbox.Measure(size.Value);
            viewbox.Arrange(new Rect(new Point(), size.Value));
            viewbox.UpdateLayout();

            var renderTargetBitmap = new RenderTargetBitmap((int)(size.Value.Width * dpiX / 96.0),
                                                            (int)(size.Value.Height * dpiY / 96.0),
                                                            dpiX,
                                                            dpiY,
                                                            PixelFormats.Pbgra32);
            var drawingVisual = new DrawingVisual();

            using (var drawingContext = drawingVisual.RenderOpen())
            {
                var visualBrush = new VisualBrush(viewbox);
                drawingContext.DrawRectangle(visualBrush, null, new Rect(new Point(), size.Value));
            }
            renderTargetBitmap.Render(drawingVisual);
            // Disassociate the frameworkElement from the viewbox
            viewbox.RemoveChild(frameworkElement);
            return(renderTargetBitmap);
        }
示例#10
0
        public static ImageSource Render(int width, int height, VectorGraphicsInfo vectorGraphicsInfo)
        {
            DpiScale    dpiInfo     = VisualTreeHelper.GetDpi(App.Current.MainWindow);
            PixelFormat pixelFormat = PixelFormats.Pbgra32;

            var x = new RenderTargetBitmap(width, height, dpiInfo.PixelsPerInchX / dpiInfo.DpiScaleX, dpiInfo.PixelsPerInchY / dpiInfo.DpiScaleY, pixelFormat);

            var canvas = new Canvas
            {
                Width  = vectorGraphicsInfo.Viewbox.Width,
                Height = vectorGraphicsInfo.Viewbox.Height,
                SnapsToDevicePixels = false,
                UseLayoutRounding   = true
            };

            foreach (Path path in vectorGraphicsInfo.Paths)
            {
                canvas.Children.Add(path);
            }

            var viewbox = new Viewbox
            {
                Stretch             = Stretch.Fill,
                Width               = width,
                Height              = height,
                SnapsToDevicePixels = false,
                UseLayoutRounding   = true,
                Child               = canvas
            };

            var size = new Size(width, height);

            viewbox.Measure(size);
            viewbox.Arrange(new Rect(size));

            x.Render(viewbox);

            x.Freeze();

            return(x);
        }
示例#11
0
        public static string GenerateChart(List <string> GivenAwnsers, string chartType)
        {
            var awn = GivenAwnsers.Distinct().OrderBy(a => a).ToArray();
            ChartValues <int> values = new ChartValues <int>();

            foreach (var l in awn)
            {
                values.Add(GivenAwnsers.Where(x => x.Equals(l)).Count());
            }

            Chart myChart;

            if (chartType == "Bar")
            {
                myChart = GenerateBar(awn, values);
            }
            else if (chartType == "Row")
            {
                myChart = GenerateRow(awn, values);
            }
            else
            {
                myChart = GeneratePie(awn, values);
            }


            var viewbox = new Viewbox();

            viewbox.Child = myChart;
            viewbox.Measure(myChart.RenderSize);
            viewbox.Arrange(new Rect(new Point(0, 0), myChart.RenderSize));
            myChart.Update(true, true); //force chart redraw
            viewbox.UpdateLayout();

            var name = DateTime.Now.ToString("dd-mm-yyyy-hh-mm-ss-fff") + ".png";

            SaveToPng(myChart, name);


            return(Location + name);
        }
示例#12
0
        public void Viewbox_Stretch_UniformToFill_Child()
        {
            using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);

            var target = new Viewbox()
            {
                Stretch = Stretch.UniformToFill, Child = new Rectangle()
                {
                    Width = 100, Height = 50
                }
            };

            target.Measure(new Size(200, 200));
            target.Arrange(new Rect(new Point(0, 0), target.DesiredSize));

            Assert.Equal(new Size(200, 200), target.DesiredSize);

            Assert.True(TryGetScale(target, out Vector scale));
            Assert.Equal(4.0, scale.X);
            Assert.Equal(4.0, scale.Y);
        }
示例#13
0
        public void Viewbox_Stretch_Uniform_Child_With_Unrestricted_Height()
        {
            using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);

            var target = new Viewbox()
            {
                Child = new Rectangle()
                {
                    Width = 100, Height = 50
                }
            };

            target.Measure(new Size(200, double.PositiveInfinity));
            target.Arrange(new Rect(new Point(0, 0), target.DesiredSize));

            Assert.Equal(new Size(200, 100), target.DesiredSize);

            Assert.True(TryGetScale(target, out Vector scale));
            Assert.Equal(2.0, scale.X);
            Assert.Equal(2.0, scale.Y);
        }
示例#14
0
        public void Viewbox_Stretch_Uniform_Child_With_Unrestricted_Width()
        {
            using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);

            var target = new Viewbox()
            {
                Child = new Rectangle()
                {
                    Width = 100, Height = 50
                }
            };

            target.Measure(new Size(double.PositiveInfinity, 200));
            target.Arrange(new Rect(new Point(0, 0), target.DesiredSize));

            Assert.Equal(new Size(400, 200), target.DesiredSize);
            var scaleTransform = target.InternalTransform as ScaleTransform;

            Assert.NotNull(scaleTransform);
            Assert.Equal(4.0, scaleTransform.ScaleX);
            Assert.Equal(4.0, scaleTransform.ScaleY);
        }
示例#15
0
        private void btnReport_Click(object sender, RoutedEventArgs e)
        {
            if (grdToPrint.Visibility == Visibility.Collapsed)
            {
                MyMessageBox.Show("يجب عرض التقرير اولاً");
                return;
            }

            //var uc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "VoucherReportTemplate.xaml")) as UserControl;

            // Create the print dialog object and set options
            PrintDialog pDialog = new PrintDialog();

            pDialog.PageRangeSelection            = PageRangeSelection.AllPages;
            pDialog.UserPageRangeEnabled          = true;
            pDialog.PrintQueue                    = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
            pDialog.PrintTicket                   = pDialog.PrintQueue.DefaultPrintTicket;
            pDialog.PrintTicket.PageScalingFactor = 1;

            System.Printing.PrintCapabilities capabilities = null;
            try
            { capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket); }
            catch
            { capabilities = null; }
            sv.Content = null;
            Viewbox vb = new Viewbox();

            vb.Child = grdToPrint;

            System.Windows.Size sz = new Size(760, grdToPrint.ActualHeight);
            vb.MinWidth  = 1;
            vb.MinHeight = 1;
            vb.Measure(sz);
            vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            pDialog.PrintVisual(vb, "MyViewBox");
            vb.Child   = null;
            sv.Content = grdToPrint;
        }
示例#16
0
        private static Brush PrepareBrush(string value)
        {
            TextBlock textBlock = new TextBlock()
            {
                Text = value, Background = value == "1" ? Brushes.LawnGreen: Brushes.Yellow
            };
            Size    size    = new Size(40, 40);
            Viewbox viewBox = new Viewbox();

            viewBox.Child = textBlock;
            viewBox.Measure(size);
            viewBox.Arrange(new Rect(size));
            RenderTargetBitmap bitmap = new RenderTargetBitmap(35, 40, 80, 80, PixelFormats.Pbgra32);

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            bitmap.Render(viewBox);

            return(new ImageBrush(bitmap));
        }
示例#17
0
        private void MergeTiles(FileInfo targetFile, XkcdTile topLeftTile, XkcdTile topRightTile, XkcdTile bottomLeftTile, XkcdTile bottomRightTile)
        {
            if (topLeftTile != null ||
                topRightTile != null ||
                bottomLeftTile != null ||
                bottomRightTile != null)
            {
                Func <XkcdTile, Image> TileToImage = tile => new Image {
                    Source = XkcdTile.ToImageSource(tile)
                };

                var grid = new UniformGrid {
                    Rows = 2, Columns = 2
                };
                grid.Children.Add(TileToImage(topLeftTile));
                grid.Children.Add(TileToImage(topRightTile));
                grid.Children.Add(TileToImage(bottomLeftTile));
                grid.Children.Add(TileToImage(bottomRightTile));

                var viewBox = new Viewbox();
                viewBox.Child = grid;

                viewBox.Measure(new System.Windows.Size(XkcdTile.Width, XkcdTile.Height));
                viewBox.Arrange(new Rect(new System.Windows.Size(XkcdTile.Width, XkcdTile.Height)));

                var renderTarget = new RenderTargetBitmap(XkcdTile.Width, XkcdTile.Height, 96, 96, PixelFormats.Default);
                renderTarget.Render(viewBox);

                var frame   = BitmapFrame.Create(renderTarget);
                var encoder = new PngBitmapEncoder {
                    Frames = new[] { frame }
                };

                using (var fileStream = targetFile.Create())
                {
                    encoder.Save(fileStream);
                }
            }
        }
示例#18
0
        public void Viewbox_Stretch_UniformToFill_Child()
        {
            using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);

            var target = new Viewbox()
            {
                Stretch = Stretch.UniformToFill, Child = new Rectangle()
                {
                    Width = 100, Height = 50
                }
            };

            target.Measure(new Size(200, 200));
            target.Arrange(new Rect(new Point(0, 0), target.DesiredSize));

            Assert.Equal(new Size(200, 200), target.DesiredSize);
            var scaleTransform = target.Child.RenderTransform as ScaleTransform;

            Assert.NotNull(scaleTransform);
            Assert.Equal(4.0, scaleTransform.ScaleX);
            Assert.Equal(4.0, scaleTransform.ScaleY);
        }
示例#19
0
        /// <summary>
        /// Render a Visual to a render target of a fixed size. The visual is
        /// scaled uniformly to fit inside the specified size.
        /// </summary>
        /// <param name="visual"></param>
        /// <param name="height"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        private static RenderTargetBitmap RenderVisual(Visual visual, double height, double width)
        {
            // Default dpi settings
            const double dpiX = 96;
            const double dpiY = 96;

            // We can only render UIElements...ContentPrensenter to
            // the rescue!
            var presenter = new ContentPresenter {
                Content = visual
            };

            // Ensure the final visual is of the known size by creating a viewbox
            // and adding the visual as its child.
            var viewbox = new Viewbox {
                MaxWidth  = width,
                MaxHeight = height,
                Stretch   = Stretch.Uniform,
                Child     = presenter
            };

            // Force the viewbox to re-size otherwise we wont see anything.
            var sFinal = new Size(viewbox.MaxWidth, viewbox.MaxHeight);

            viewbox.Measure(sFinal);
            viewbox.Arrange(new Rect(sFinal));
            viewbox.UpdateLayout();

            // Render the final visual to a render target
            var renderTarget = new RenderTargetBitmap(
                (int)width, (int)height, dpiX, dpiY, PixelFormats.Pbgra32);

            renderTarget.Render(viewbox);

            // Return the render taget with the visual rendered on it.
            return(renderTarget);
        }
示例#20
0
        public static Canvas ToCanvas(this BookPage bookPage, PaperSize paperSize)
        {
            double width  = paperSize.GetWidthPixel();
            double height = paperSize.GetHeightPiexl();

            Canvas canvas = new Canvas()
            {
                Width  = width,
                Height = height
            };

            canvas.Background = bookPage.Background == null
                ? (Brush)Brushes.White
                : new ImageBrush((BitmapSource) new ImageSourceConverter().ConvertFrom(bookPage.Background))
            {
                Stretch = Stretch.Fill
            };


            foreach (UIElement element in bookPage.ToUIElementCollection())
            {
                canvas.Children.Add(element);
            }

            // Viewbox can render controls in code behind
            var viewbox = new Viewbox()
            {
                Child = canvas
            };

            viewbox.Measure(new Size(width, height));
            viewbox.Arrange(new Rect(0, 0, width, height));
            viewbox.UpdateLayout();
            viewbox.Child = null;
            return(canvas);
        }
示例#21
0
        internal static void printReportA6(Order o)
        {
            try
            {
                if (o.Type < 3)
                {
                    var uc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "VoucherReportTemplate.xaml")) as UserControl;
                    uc.DataContext = o;
                    (uc.FindName("Items") as ItemsControl).ItemsSource = from x in o.OIs select new { ItemName = x.Item.Name, Quantity = x.Quantity, StandardUnit = x.Item.StandardUnit };
                    (uc.FindName("txtTag") as TextBlock).Text          = "1/1";
                    (uc.FindName("txtHeader") as TextBlock).Text       = Properties.Settings.Default.VoucherHeaderText;
                    (uc.FindName("grdFamily") as Grid).Visibility      = Visibility.Collapsed;
                    (uc.FindName("grdOrder") as Grid).Visibility       = Visibility.Visible;

                    var         img    = uc.FindName("img") as Image;
                    BitmapImage bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute);
                    bitmap.EndInit();
                    img.Source = bitmap;

                    // Create the print dialog object and set options
                    PrintDialog pDialog = new PrintDialog();
                    pDialog.PageRangeSelection            = PageRangeSelection.AllPages;
                    pDialog.UserPageRangeEnabled          = true;
                    pDialog.PrintQueue                    = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
                    pDialog.PrintTicket                   = pDialog.PrintQueue.DefaultPrintTicket;
                    pDialog.PrintTicket.PageScalingFactor = 1;

                    System.Printing.PrintCapabilities capabilities = null;
                    try
                    {
                        capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket);
                    }
                    catch
                    {
                        capabilities = null;
                    }
                    Viewbox vb = new Viewbox();
                    vb.Child = uc;

                    System.Windows.Size sz = new Size(520, 380);
                    vb.MinWidth  = 1;
                    vb.MinHeight = 1;
                    vb.Measure(sz);
                    vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                    double scale = 1;
                    vb.LayoutTransform = new ScaleTransform(scale, scale);

                    pDialog.PrintVisual(vb, "MyViewBox");
                }
                else if (o.Type == 3)
                {
                    var dtVoucherCriteria = BaseDataBase._Tabling($@"select IsNull(GroupID,-1) GroupID,Item.Name ItemName, Quantity, StandardUnit from
                                    (select ItemID, Quantity from Order_Item where OrderID = {o.Id}) t1 
                                    inner join Item on t1.ItemID = item.Id
                                    left outer join VoucherCriteria t2
                                    on t1.ItemID = t2.ItemID");
                    if (dtVoucherCriteria != null && dtVoucherCriteria.Rows.Count > 0)
                    {
                        List <DataTable> subTables = dtVoucherCriteria.AsEnumerable().GroupBy(row => row.Field <int>("GroupID")).Select(g => g.CopyToDataTable()).ToList();
                        if (subTables.Count > 1)
                        {
                            MyMessageBox.Show("ستم طباعة " + subTables.Count + " وصل");
                        }

                        var dt = BaseDataBase._Tabling($@"select OrderCode Id,[Order].Barcode, dbo.GetInventory(InventoryID) InventoryName,dbo.fn_getSectorByOrderID([Order].Id) Sector, 
	                            Family.FamilyID FamilyCode, 
	                            case when FatherName is not null then FatherName else (case when MotherName is not null then MotherName else FamilyName end) end as FatherName, 
	                            case when FatherPID is not null then FatherPID else (case when MotherPID is not null then MotherPID else 'لايوجد رقم وطني' end) end as PID, 
	                            NextOrderDate,
                                Date, Users.Name Presenter from [Order]
                                inner join Family on [Order].Id = {o.Id} and Family.FamilyID = [Order].FamilyID
                                inner join Users on Users.Id = [Order].LastUserID 
                                left outer join
                                (select FirstName + ' ' + IsNUll(LastName,'') FatherName ,PID FatherPID, FamilyID from Parent where Gender like N'ذكر') x 
                                on x.FamilyID = [Order].FamilyID
	                            left outer join
	                            (select FirstName + ' ' + IsNUll(LastName,'') MotherName ,PID MotherPID, FamilyID from Parent where Gender like N'أنثى') y 
                                on y.FamilyID = [Order].FamilyID");

                        for (int i = 0; i < subTables.Count; i++)
                        {
                            var uc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "VoucherReportTemplate.xaml")) as UserControl;
                            uc.DataContext = null;
                            uc.DataContext = dt.DefaultView;
                            (uc.FindName("Items") as ItemsControl).ItemsSource = subTables[i].DefaultView;
                            (uc.FindName("txtTag") as TextBlock).Text          = (i + 1) + "/" + subTables.Count;
                            (uc.FindName("txtHeader") as TextBlock).Text       = Properties.Settings.Default.VoucherHeaderText;

                            var         img    = uc.FindName("img") as Image;
                            BitmapImage bitmap = new BitmapImage();
                            bitmap.BeginInit();
                            bitmap.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute);
                            bitmap.EndInit();
                            img.Source = bitmap;

                            // Create the print dialog object and set options
                            PrintDialog pDialog = new PrintDialog();
                            pDialog.PageRangeSelection            = PageRangeSelection.AllPages;
                            pDialog.UserPageRangeEnabled          = true;
                            pDialog.PrintQueue                    = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
                            pDialog.PrintTicket                   = pDialog.PrintQueue.DefaultPrintTicket;
                            pDialog.PrintTicket.PageScalingFactor = 1;

                            System.Printing.PrintCapabilities capabilities = null;
                            try
                            {
                                capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket);
                            }
                            catch
                            {
                                capabilities = null;
                            }
                            Viewbox vb = new Viewbox();
                            vb.Child = uc;

                            System.Windows.Size sz = new Size(520, 380);
                            vb.MinWidth  = 1;
                            vb.MinHeight = 1;
                            vb.Measure(sz);
                            vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                            double scale = 1;
                            vb.LayoutTransform = new ScaleTransform(scale, scale);

                            pDialog.PrintVisual(vb, "MyViewBox");
                        }
                    }
                }
                else
                {
                    var dtVoucherCriteria = BaseDataBase._Tabling($@"select IsNull(GroupID,-1) GroupID,Item.Name ItemName, Quantity, StandardUnit from
                                    (select ItemID, Quantity from Order_Item where OrderID = {o.Id}) t1 
                                    inner join Item on t1.ItemID = item.Id
                                    left outer join VoucherCriteria t2
                                    on t1.ItemID = t2.ItemID");
                    if (dtVoucherCriteria != null && dtVoucherCriteria.Rows.Count > 0)
                    {
                        List <DataTable> subTables = dtVoucherCriteria.AsEnumerable().GroupBy(row => row.Field <int>("GroupID")).Select(g => g.CopyToDataTable()).ToList();
                        if (subTables.Count > 1)
                        {
                            MyMessageBox.Show("ستم طباعة " + subTables.Count + " وصل");
                        }

                        var dt = BaseDataBase._Tabling($@"select OrderCode Id,[Order].Barcode, dbo.GetInventory(InventoryID) InventoryName,'عائلة خاصة' Sector, SpecialFamily.Id FamilyCode, SpecialFamily.Name FatherName, PID,
                                            Date, Users.Name Presenter from [Order]
                                            inner join SpecialFamily on [Order].Id = {o.Id} and SpecialFamily.Id = [Order].SpecialFamilyID
                                            inner join Users on Users.Id = [Order].LastUserID");


                        for (int i = 0; i < subTables.Count; i++)
                        {
                            var uc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "VoucherReportTemplate.xaml")) as UserControl;
                            uc.DataContext = null;
                            uc.DataContext = dt;
                            (uc.FindName("Items") as ItemsControl).ItemsSource = subTables[i].DefaultView;
                            (uc.FindName("txtTag") as TextBlock).Text          = (i + 1) + "/" + subTables.Count;
                            (uc.FindName("txtHeader") as TextBlock).Text       = Properties.Settings.Default.VoucherHeaderText;
                            //(uc.FindName("Items") as ItemsControl).ItemsSource = from x in o.OIs select new { ItemName = x.Item.Name, Quantity = x.Quantity, StandardUnit = x.Item.StandardUnit };
                            //(uc.FindName("txtTag") as TextBlock).Text = "1/1";

                            var         img    = uc.FindName("img") as Image;
                            BitmapImage bitmap = new BitmapImage();
                            bitmap.BeginInit();
                            bitmap.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute);
                            bitmap.EndInit();
                            img.Source = bitmap;

                            // Create the print dialog object and set options
                            PrintDialog pDialog = new PrintDialog();
                            pDialog.PageRangeSelection            = PageRangeSelection.AllPages;
                            pDialog.UserPageRangeEnabled          = true;
                            pDialog.PrintQueue                    = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
                            pDialog.PrintTicket                   = pDialog.PrintQueue.DefaultPrintTicket;
                            pDialog.PrintTicket.PageScalingFactor = 1;

                            System.Printing.PrintCapabilities capabilities = null;
                            try
                            {
                                capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket);
                            }
                            catch
                            {
                                capabilities = null;
                            }
                            Viewbox vb = new Viewbox();
                            vb.Child = uc;

                            System.Windows.Size sz = new Size(520, 380);
                            vb.MinWidth  = 1;
                            vb.MinHeight = 1;
                            vb.Measure(sz);
                            vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                            double scale = 1;
                            vb.LayoutTransform = new ScaleTransform(scale, scale);

                            pDialog.PrintVisual(vb, "MyViewBox");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.Show(ex.Message);
            }
        }
示例#22
0
        public bool ExportCore(Project Project, string FileName)
        {
            // Create a new canvas and set its background. This is what we are going to be rendering to.
            Canvas TempCanvas = new Canvas();

            MainWindow Xwindow = (MainWindow)Application.Current.MainWindow;

            BitmapImage Bitmap = new BitmapImage();

            Bitmap.BeginInit();
            Bitmap.UriSource = new Uri(Project.SelectedBasin.ImagePath, UriKind.RelativeOrAbsolute);
            Bitmap.EndInit();
            // dumb hack (build 558)

            TempCanvas.Background = new ImageBrush(Bitmap);

            Point CanvasSize = ScaleUtilities.ScaleToQuality(Bitmap, Quality);

            TempCanvas.Width  = CanvasSize.X;
            TempCanvas.Height = CanvasSize.Y;

            Project CurrentProject = Xwindow.CurrentProject;

            //
            //CurrentProject.SelectedBasin.RecalculateNodePositions(Direction.Larger, new Point(Xwindow.Width, Xwindow.Height), new Point(TempCanvas.Width, TempCanvas.Height));

            //New scaling for picking up dev again - 2020-05-08 23:04
            //Remove storm selection functionality, replace with layer selection functionality - 2020-09-12 17:24
            //v462 - 2020-09-26 00:00
            Xwindow.RenderContent(TempCanvas, new Point(Utilities.RoundNearest(8 * (TempCanvas.Width / Xwindow.Width) / 1.5, 8), Utilities.RoundNearest(8 * (TempCanvas.Height / Xwindow.Height) / 1.5, 8)), Project.SelectedBasin.GetFlatListOfStorms());

            // Recalculate node positions on the currentbasin so they actually show up properly.

            TempCanvas.UpdateLayout();

            // create a new rendertargetbitmap and render to it

            RenderTargetBitmap RenderTarget = new RenderTargetBitmap((int)TempCanvas.Width, (int)TempCanvas.Height, 96.0, 96.0, PixelFormats.Default);

            // force WPF to render it because optimization is not always a good idea

            Viewbox ViewBox = new Viewbox();

            ViewBox.Child = TempCanvas;
            ViewBox.Measure(new Size(TempCanvas.Width, TempCanvas.Height));
            ViewBox.Arrange(new Rect(new Point(0, 0), new Point(TempCanvas.Width, TempCanvas.Height)));
            ViewBox.UpdateLayout();

            RenderTarget.Render(TempCanvas);

            // create a new PNG encoder and memory stream

            ImageFormats ImgFormat = ImageFormatDeterminer.FromString(FileName);
            // REFACTOR PROBABLY
            BitmapEncoder PNGEncoder = ImageFormatDeterminer.GetBitmapEncoder(ImgFormat);

            if (PNGEncoder == null)
            {
                Error.Throw("Warning", "Error: unable to determine image format", ErrorSeverity.Error, 361);
                return(false);
            }

            PNGEncoder.Frames.Add(BitmapFrame.Create(RenderTarget));

            MemoryStream TempCanvasms_ = new MemoryStream();

            // save the thing

            PNGEncoder.Save(TempCanvasms_);
            File.WriteAllBytes(FileName, TempCanvasms_.ToArray());

            // clean up by restoring the basin
            //CurrentProject.SelectedBasin.RecalculateNodePositions(Direction.Smaller, new Point(Xwindow.Width, Xwindow.Height), new Point(TempCanvas.Width, TempCanvas.Height));

            // on success
            GlobalState.SetCurrentOpenFile(FileName);

            return(true); // success
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Chart3.Height            = 500;
            Chart3.Width             = 1000;
            Chart3.AxisX[0].MinValue = double.NaN;
            Chart3.AxisX[0].MaxValue = double.NaN;
            Chart3.AxisY[0].MinValue = double.NaN;
            Chart3.AxisY[0].MaxValue = double.NaN;

            var myChart = new LiveCharts.Wpf.CartesianChart
            {
                DisableAnimations = true,
                Width             = 1200,
                Height            = 400,
                Series            = new SeriesCollection
                {
                    new LineSeries
                    {
                        Title  = "Neutral",
                        Values = cv_net3
                    },
                    new LineSeries
                    {
                        Title  = "Anger",
                        Values = cv_ang3
                    },
                    new LineSeries
                    {
                        Title  = "Disgust",
                        Values = cv_dis3
                    },
                    new LineSeries
                    {
                        Title  = "Fear",
                        Values = cv_fea3
                    },
                    new LineSeries
                    {
                        Title  = "Happy",
                        Values = cv_hap3
                    },
                    new LineSeries
                    {
                        Title  = "Saddness",
                        Values = cv_sad3
                    },
                    new LineSeries
                    {
                        Title  = "Surprise",
                        Values = cv_sur3
                    },
                }
            };
            var viewbox = new Viewbox();

            viewbox.Child = myChart;
            viewbox.Measure(myChart.RenderSize);
            viewbox.Arrange(new Rect(new System.Windows.Point(0, 0), myChart.RenderSize));
            myChart.Update(true, true); //force chart redraw
            viewbox.UpdateLayout();

            SaveToPng(myChart, "chart.png");
            //png file was created at the root directory.

            Chart3.Height = 178;
            Chart3.Width  = 324;
        }
示例#24
0
        //сохранение графика как картинку
        private void SaveFile(string _fileName, string pathForSave)
        {
            var save = DataContext as MainWindiwViewModel;
            ChartValues <double> valueLeft  = null;
            ChartValues <double> valueRight = null;
            string titleAxisY = null;

            //выбор данных
            switch (_fileName)
            {
            case "График Вертикальных силы ":
                valueLeft  = save.selectedForce.LeftVerticalForMovingAverage;
                valueRight = save.selectedForce.RightVerticalForMovingAverage;
                titleAxisY = "Вертикальные силы, кН";
                break;

            case "График Боковых силы ":
                valueLeft  = save.selectedForce.LeftLateralForMovingAverage;
                valueRight = save.selectedForce.RightLateralForMovingAverage;
                titleAxisY = "Боковых силы, кН";
                break;

            case "График Коэффициента запаса от схода ":
                valueLeft  = save.selectedForce.LeftSafetyFactorForMovingAverage;
                valueRight = save.selectedForce.RightSafetyFactorForMovingAverage;
                titleAxisY = "Коэффициент запаса от схода";
                break;
            }
            //создавание графика
            if (save.selectedForce != null)
            {
                var myChart = new CartesianChart
                {
                    DataTooltip       = null,
                    DisableAnimations = true,
                    Hoverable         = true,
                    LegendLocation    = LegendLocation.Bottom,
                    Width             = 1920,
                    Height            = 1080,
                    Series            = new SeriesCollection
                    {
                        new LineSeries
                        {
                            StrokeThickness   = 1,
                            LineSmoothness    = 1,
                            Title             = "Левое колесо",
                            Stroke            = Brushes.Blue,
                            Fill              = Brushes.Transparent,
                            PointGeometrySize = 6,
                            PointForeground   = Brushes.White,
                            PointGeometry     = null,
                            Values            = valueLeft
                        },
                        new LineSeries
                        {
                            StrokeThickness   = 1,
                            LineSmoothness    = 1,
                            Title             = "Правое колесо",
                            Stroke            = Brushes.Red,
                            Fill              = Brushes.Transparent,
                            PointGeometrySize = 6,
                            PointForeground   = Brushes.Gold,
                            PointGeometry     = null,
                            Values            = valueRight
                        }
                    }
                };

                var _AxisAbscissa = new Axis();
                _AxisAbscissa.Title  = "Время,сек";
                _AxisAbscissa.Labels = save.selectedForce.TimeForMovingAverage;
                myChart.AxisX.Add(_AxisAbscissa);

                var _AxisOrdinate = new Axis();
                _AxisOrdinate.Title = titleAxisY;
                myChart.AxisY.Add(_AxisOrdinate);

                var viewbox = new Viewbox();
                viewbox.Child = myChart;
                viewbox.Measure(myChart.RenderSize);
                viewbox.Arrange(new Rect(new Point(0, 0), myChart.RenderSize));
                myChart.Update(true, true);
                myChart.Background = Brushes.White;
                viewbox.UpdateLayout();
                var allName = _fileName + save.selectedForce._NameSignal + ".png";

                SaveToPng(myChart, allName, pathForSave);
            }
        }
示例#25
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     Visual.Arrange(new Rect(finalSize));
     return(finalSize);
 }
示例#26
0
        public static void printReportNew(Order order)
        {
            Family    f  = Family.GetFamilyByID(order.FamilyID.Value);
            TextBlock tb = new TextBlock();

            tb.FontFamily = new System.Windows.Media.FontFamily("Arial");
            tb.Inlines.Add(new Bold(new Run("جمعية الإحسان الخيرية التنموية بحلب")));
            tb.Inlines.Add(new LineBreak());
            tb.Inlines.Add(new LineBreak());
            tb.Inlines.Add(new Run("التاريخ " + order.Date.Value.ToString("dd/MM/yyyy hh:mm")));
            tb.Inlines.Add(new LineBreak());
            tb.Inlines.Add(new Run("المسلم " + User.GetUserNameByID(order.LastUserID)));
            tb.Inlines.Add(new LineBreak());
            tb.Inlines.Add(new Run("رمز العائلة " + f.FamilyCode));
            tb.Inlines.Add(new LineBreak());
            tb.Inlines.Add(new Run("اسم العائلة " + f.FamilyName));
            tb.Inlines.Add(new LineBreak());
            if (order.NextOrderDate.HasValue)
            {
                tb.Inlines.Add(new Run("الاستلام القادم " + order.NextOrderDate.Value.ToString("dd-MM-yyyy")));
                tb.Inlines.Add(new LineBreak());
            }
            tb.Inlines.Add(new Underline(new Run("المواد المسلّمة :")));
            tb.Inlines.Add(new LineBreak());

            // Add some Bold text to the paragraph
            for (int i = 0; i < order.OIs.Count; i++)
            {
                var x = order.OIs[i].Item;
                tb.Inlines.Add(new Run(x.Source + " " + x.Name + "\t (" + order.OIs[i].Quantity + ")"));
                tb.Inlines.Add(new LineBreak());
            }
            tb.Margin   = new Thickness(5, 2, 5, 2);
            tb.FontSize = 12;

            Grid g = new Grid();

            g.FlowDirection = FlowDirection.RightToLeft;
            g.Children.Add(tb);

            // Create the print dialog object and set options
            PrintDialog pDialog = new PrintDialog();

            pDialog.PageRangeSelection            = PageRangeSelection.AllPages;
            pDialog.UserPageRangeEnabled          = true;
            pDialog.PrintQueue                    = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
            pDialog.PrintTicket                   = pDialog.PrintQueue.DefaultPrintTicket;
            pDialog.PrintTicket.PageScalingFactor = 1;

            System.Printing.PrintCapabilities capabilities = null;
            try
            {
                capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket);
            }
            catch
            {
                capabilities = null;
            }

            Viewbox vb = new Viewbox();

            vb.Child = g;

            System.Windows.Size sz = new System.Windows.Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
            vb.MinWidth  = 1;
            vb.MinHeight = 1;
            vb.Measure(sz);
            vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / vb.ActualWidth, capabilities.PageImageableArea.ExtentHeight / vb.ActualHeight);

            vb.LayoutTransform = new ScaleTransform(scale, scale);

            pDialog.PrintVisual(vb, "MyViewBox");
        }
示例#27
0
        public static void printReport(Order order, BitmapImage bi)
        {
            try
            {
                Family    f          = Family.GetFamilyByID(order.FamilyID.Value);
                Paragraph paragraph3 = new Paragraph();
                paragraph3.FlowDirection = FlowDirection.RightToLeft;
                paragraph3.Inlines.Add(new Bold(new Run(Properties.Settings.Default.VoucherHeaderText)));
                paragraph3.Inlines.Add(new LineBreak());
                paragraph3.Inlines.Add(new LineBreak());
                paragraph3.Inlines.Add(new Run("التاريخ " + order.Date.Value.ToString("dd/MM/yyyy hh:mm")));
                paragraph3.Inlines.Add(new LineBreak());
                paragraph3.Inlines.Add(new Run("المسلم " + User.GetUserNameByID(order.LastUserID)));
                paragraph3.Inlines.Add(new LineBreak());
                paragraph3.Inlines.Add(new Run("رمز العائلة " + f.FamilyCode));
                paragraph3.Inlines.Add(new LineBreak());
                paragraph3.Inlines.Add(new Run("اسم العائلة " + f.FamilyName));
                paragraph3.Inlines.Add(new LineBreak());
                if (order.NextOrderDate.HasValue)
                {
                    paragraph3.Inlines.Add(new Run("الاستلام القادم " + order.NextOrderDate.Value.ToString("dd-MM-yyyy")));
                    paragraph3.Inlines.Add(new LineBreak());
                }
                paragraph3.Inlines.Add(new Underline(new Run("المواد المسلّمة :")));
                paragraph3.Inlines.Add(new LineBreak());

                for (int i = 0; i < order.OIs.Count; i++)
                {
                    var x = order.OIs[i].Item;
                    paragraph3.Inlines.Add(new Run(x.Source + " " + x.Name + "\t (" + order.OIs[i].Quantity + ")"));
                    paragraph3.Inlines.Add(new LineBreak());
                }

                paragraph3.FontFamily = new FontFamily("Arial");
                paragraph3.FontSize   = 16;

                FlowDocumentScrollViewer temp = new FlowDocumentScrollViewer();
                temp.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
                FlowDocument myFlowDocument = new FlowDocument();
                temp.FlowDirection           = FlowDirection.RightToLeft;
                myFlowDocument.FlowDirection = FlowDirection.RightToLeft;

                paragraph3.FlowDirection = FlowDirection.RightToLeft;
                paragraph3.Inlines.Add(new Underline(new Run("بصمة المستلم")));
                myFlowDocument.Blocks.Add(paragraph3);
                // myFlowDocument.Blocks.Add(paragraph4);
                myFlowDocument.Blocks.Add(new BlockUIContainer(new Image()
                {
                    Source = bi, Height = 100, Stretch = Stretch.Uniform
                }));

                FlowDocumentReader myFlowDocumentReader = new FlowDocumentReader();
                myFlowDocumentReader.Document = myFlowDocument;

                myFlowDocumentReader.FlowDirection = FlowDirection.RightToLeft;
                temp.Document = myFlowDocument;

                temp.FlowDirection       = FlowDirection.RightToLeft;
                temp.HorizontalAlignment = HorizontalAlignment.Center;
                temp.Width  = 250;
                temp.Height = 285 + (order.OIs.Count * 21);

                PrintDialog pDialog = new PrintDialog();
                pDialog.PageRangeSelection            = PageRangeSelection.AllPages;
                pDialog.UserPageRangeEnabled          = true;
                pDialog.PrintQueue                    = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
                pDialog.PrintTicket                   = pDialog.PrintQueue.DefaultPrintTicket;
                pDialog.PrintTicket.PageScalingFactor = 1;

                Rect printableArea = GetPrintableArea(pDialog);

                Viewbox viewBox = new Viewbox {
                    Child = temp
                };
                printableArea.Height = 285 + (order.OIs.Count * 21);
                printableArea.Width  = 250;

                viewBox.Measure(printableArea.Size);
                viewBox.Arrange(printableArea);
                pDialog.PrintVisual(viewBox, "Letter Canvas");
            }
            catch (Exception ex) { MyMessageBox.Show(ex.Message); }
        }
示例#28
0
        internal static void printInvoiceA6(Invoice i, int Type)
        {
            try
            {
                var uc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "InvoiceReportTemplate.xaml")) as UserControl;
                (uc.FindName("txtHeader") as TextBlock).Text = Properties.Settings.Default.VoucherHeaderText;
                var         img    = uc.FindName("img") as Image;
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute);
                bitmap.EndInit();
                img.Source = bitmap;

                if (Type == 1)
                {
                    uc.DataContext = BaseDataBase._Tabling($@"select Description, Barcode, TotalValue, Serial, Receiver, ReceiverPID, dbo.GetUserByID(LastUserID) UserName, CreateDate, (select Name from Account where ID = {i.Transitions[0].LeftAccount.Id.Value}) SponsorName
                                         from Invoice where Id = {i.ID.Value}");

                    (uc.FindName("grdSponsor") as Grid).Visibility = Visibility.Visible;
                }
                else if (Type == 2)
                {
                    var dv = BaseDataBase._Tabling($@"select Description, Barcode, TotalValue, Serial, Receiver, ReceiverPID, dbo.GetUserByID(LastUserID) UserName, CreateDate from Invoice where Id = {i.ID.Value}");
                    (uc.FindName("icOrphans") as ItemsControl).ItemsSource = BaseDataBase._Tabling($@"select FirstName + ' ' + ISNULL(LastName,'') OrphanName, orphan.Type, Value, Sponsor.Name SponsorName from orphan
                                            inner join Account on Account.Type >= 2 and OwnerID = OrphanID
                                            inner join Transition on InvoiceID = {i.ID.Value} and Account.Id = RightAccount
                                            inner join (select * from Sponsorship where ID in (select Max(ID) from Sponsorship group by OrphanID)) Sponsorship on Sponsorship.OrphanID = Orphan.OrphanID
                                            inner join AvailableSponsorship on AvailableSponsorship.Id = Sponsorship.AvailableSponsorshipID
                                            inner join Sponsor on AvailableSponsorship.SponsorID = Sponsor.SponsorID").DefaultView;

                    uc.DataContext = dv;
                    (uc.FindName("grdOrphan") as Grid).Visibility = Visibility.Visible;
                    var w = new ToWord(decimal.Parse(dv.Rows[0]["TotalValue"].ToString()), new CurrencyInfo(CurrencyInfo.Currencies.Syria));
                    (uc.FindName("TotalValueWord") as TextBlock).Text = w.ConvertToArabic();
                }

                // Create the print dialog object and set options
                PrintDialog pDialog = new PrintDialog();
                pDialog.PageRangeSelection            = PageRangeSelection.AllPages;
                pDialog.UserPageRangeEnabled          = true;
                pDialog.PrintQueue                    = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
                pDialog.PrintTicket                   = pDialog.PrintQueue.DefaultPrintTicket;
                pDialog.PrintTicket.PageScalingFactor = 1;

                System.Printing.PrintCapabilities capabilities = null;
                try
                {
                    capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket);
                }
                catch
                {
                    capabilities = null;
                }
                Viewbox vb = new Viewbox();
                vb.Child = uc;

                System.Windows.Size sz = new Size(520, 380);
                vb.MinWidth  = 1;
                vb.MinHeight = 1;
                vb.Measure(sz);
                vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                double scale = 1;
                vb.LayoutTransform = new ScaleTransform(scale, scale);

                pDialog.PrintVisual(vb, "MyViewBox");
            }
            catch (Exception ex)
            {
                MyMessageBox.Show(ex.Message);
            }
        }