I have set up the following routine to print a scaled version of a FrameworkElement:
public void PrintUI(FrameworkElement element) { PrintDialog printDialog = new PrintDialog(); printDialog.PrintQueue = PrinterItem.Printer; printDialog.PrintTicket.PageOrientation = PageOrientation; printDialog.PrintTicket.PageMediaSize = PageMediaSize; System.Printing.PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket); double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / element.ActualWidth, capabilities.PageImageableArea.ExtentHeight / element.ActualHeight); Transform currentTransform = element.RenderTransform; double currentWidth = element.ActualWidth; double currentHeight = element.ActualHeight; element.RenderTransform = new ScaleTransform(scale, scale); Size size = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); element.Measure(size); element.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), size)); printDialog.PrintVisual(element, VisualName); element.RenderTransform = currentTransform; size = new Size(currentWidth, currentHeight); element.Measure(size); element.Arrange(new Rect(size)); }
The PrintQueue, PageMediaSize, and PageOrientation are selected by the user. This seems to work ok for Adobe PDF printer or my physical printer. When I try to use the XPS Document Printer the FrameworkElement gets scaled but the print does not seem to honor the page size specified in the ticket. So I end up with a portion of my scaled FrameworkElement showing up on a page that matches the size prior to scaling.
Is there a way that I can enforce the page size with the XPS Document Printer?