WPF Reflections

May 14 2008   8:50AM GMT

WPF Printing documents

Mark Shurmer Profile: MarkWPF

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)

prtDlg.PrintDocument(((IDocumentPaginatorSource)docRdr.Document).DocumentPaginator, “Statement”);


This will print the document for you just fine

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: