FlowDocument is probably the best solution for dynamic content and dynamic print size, i.e. either unknown or subject to change. For my problem, I knew both the content and print size.
The first thing I did was set the content in ScrollViewer, the grid in my case, to A4 size, which can be easily done with
<Grid x:Name="gridReport" Height="29.7cm" Width="21cm">
This means that the grid is displayed exactly in the print area, and everything inside the grid should not be distorted when printing.
This still cuts off the top area if the ScrollViewer was not scrolled to the top at the point of use of PrintDialog. To solve this problem programmatically, before printing, click
Myscrollviewer.ScrollToTop(); PrintDialog printDialog = new PrintDialog(); if(printDialog.ShowDialog() == true) { printDialog.PrintVisual(gridReport, "Print Report"); }
source share