I was playing around with Petzold's PrintWithMargins program from chapter 17 in his book "Applications = Code + Markup". The code is available athttp://www.microsoft.com/mspress/companion/0-7356-1957-3/. The problem can be boiled down to having a window with a print button. The Click handler is as follows:
void PrintOnClick(object sender, RoutedEventArgs args) { PrintDialog dialog = new PrintDialog();if (dialog.ShowDialog().GetValueOrDefault()) { DrawingVisual visual = new DrawingVisual(); DrawingContext context = visual.RenderOpen(); Pen pen = new Pen(Brushes.Black, 1); Rect borderRect = new Rect(96, 96, dialog.PrintableAreaWidth - 2 * 96, dialog.PrintableAreaHeight - 2 * 96); context.DrawRectangle(null, pen, borderRect); context.Close(); dialog.PrintVisual(visual, Title); } }
So, it is just drawing a rectangle one inch from the edge of the printable area. I'm printing using Microsoft XPS Document Writer on Windows 7. The print dialog allows the user to choose orientation, Landscape or Portrait. The choice is reflected in different values for PrintableAreaWidth and PrintableAreaHeight. However, when using landscape orientation the resulting XPS document still displays (using XPS Viewer) as it had portrait orientation. The drawn rectangle is wider than tall, but is cut off on the right.
I have the feeling that I need to do something additionally to indicate that the final document has height 8.5" and width 11".