private void Print(Visual v) { FrameworkElement e = v as FrameworkElement; if (e == null) return; PrintDialog pd = new PrintDialog(); if (pd.ShowDialog() == true) { //store original scale Transform originalScale = e.LayoutTransform; //get selected printer capabilities var capabilities = pd.PrintQueue.GetPrintCapabilities(pd.PrintTicket); //get scale of the print wrt to screen of WPF visual double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / e.ActualWidth, capabilities.PageImageableArea.ExtentHeight / e.ActualHeight); //Transform the Visual to scale e.LayoutTransform = new ScaleTransform(scale, scale); //get the size of the printer page Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); //update the layout of the visual to the printer page size. e.Measure(sz); e.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); //now print the visual to printer to fit on the one page. pd.PrintVisual(v, "My Print"); //apply the original transform. e.LayoutTransform = originalScale; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)