Posted by: MarkWPF
printing, WPF, XAML
I have blogged before on how you print a WPF element using the PrintVisual method in the PrintDialog class, which is very flexible as it will print any element derived from Systems.Windows.Media.Visual.
However, there is another weapon in the PrintDialog armoury, and that is the ability to print documents. Given the extensive document support in WPF, it comes as no surprise that you can easily print these documents.
To do that you need to get at the DocumentPaginator object – it’s purpose in life lies in managing content as pages which is just perfect for the job.
You get at it by using the IDocumentPaginatorSource interface, like this:
assuming docRdr is a FlowDocumentScrollViewer
PrintDialog prtDlg = new PrintDialog();
if(prtDlg.ShowDialog() == true)
This will print the document for you just fine