I've written a small app which creates a visual programmatically, and I'm trying to print it out on a page in landscape orientation (it clips in portrait). When I print, it does come out in landscape, but my visual is still clipped as through it were limited to portrait orientation.
Here's my code:
StackPanel page = new StackPanel();
// ... generate stuff to the page to create the visual
PrintDialog dialog = new PrintDialog(); // System.Windows.Controls.PrintDialog
bool? result = dialog.ShowDialog();
if(result.HasValue && result.Value)
{
dialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
Size pageSize = new Size { Width = dialog.PrintableAreaWidth,
Height = dialog.PrintableAreaHeight };
// pageSize comes out to {1056, 816}, which is the orientation I expect
page.Measure(pageSize);
// after this, page.DesiredSize is e.g. {944, 657}, wider than portrait (816).
page.UpdateLayout();
dialog.PrintVisual(page, "Job description");
}
After executing this, the printed content is arranged correctly but still seems to be clipped to a width of 816, cutting off a significant chunk of content. I've checked this by holding another piece of paper over the printed one and it fits perfectly inside.
Is there something I'm doing wrong to measure and arrange the controls? How can I get my printer to use the full space of landscape orientation?