示例#1
0
        public static void PrintWithDPI(GraphAreaBase visual, string description, double dpi, int margin = 0)
        {
            var pd = new PrintDialog();

            if (pd.ShowDialog() == true)
            {
                visual.SetPrintMode(true, true, margin);
                //store original scale
                var originalScale = visual.LayoutTransform;
                //get scale from DPI
                var scale = dpi / DEFAULT_DPI;
                //Transform the Visual to scale
                var group = new TransformGroup();
                group.Children.Add(new ScaleTransform(scale, scale));
                visual.LayoutTransform = group;
                //update visual
                visual.InvalidateArrange();
                visual.UpdateLayout();

                //now print the visual to printer to fit on the one page.
                pd.PrintVisual(visual, description);
                //apply the original transform.
                visual.LayoutTransform = originalScale;
                visual.SetPrintMode(false, true, margin);
            }
        }
示例#2
0
        public static void PrintToFit(GraphAreaBase visual, string description, int margin = 0)
        {
            var pd = new PrintDialog();

            if (pd.ShowDialog() == true)
            {
                visual.SetPrintMode(true, true, margin);

                //store original scale
                var originalScale = visual.LayoutTransform;
                //get selected printer capabilities
                var capabilities = pd.PrintQueue.GetPrintCapabilities(pd.PrintTicket);

                //get scale of the print wrt to screen of WPF visual
                var scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / visual.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
                                     visual.ActualHeight);

                //Transform the Visual to scale
                var group = new TransformGroup();
                group.Children.Add(new ScaleTransform(scale, scale));
                visual.LayoutTransform = group;
                visual.InvalidateArrange();
                visual.UpdateLayout();

                //now print the visual to printer to fit on the one page.
                pd.PrintVisual(visual, description);

                //apply the original transform.
                visual.LayoutTransform = originalScale;
                visual.SetPrintMode(false, true, margin);
            }
        }