Printing in Windows Presentation Foundation

Learn how to use PrintDialog, PrintVisual and DocumentPaginator to print in Windows Presentation Foundation (WPF).

How does printing work in Windows Presentation Foundation (WPF)? We gathered some helpful excerpts and examples from the WPF Reflections blog, by Mark Shurmer below.


If you have ever worked with printing in MFC, then printing in Windows Presentation Foundation is so advanced, as to make you dizzy. Even if you ever tried printing with Windows Forms, then printing in WPF is a bit of a revelation.

How does it work?

Most of the printing stuff is in the System.Printing namespace, and a good starting place is the PrintDialog class. By instantiating the PrintDialog class, you can display the standard XP or Vista print dialog to allow the user to choose where to print, and how.

What else does it give you?

You can call two different methods to do printing. PrintVisual allows you to print any class that derives from System.Windows.Media.Visual, which is a lot. And PrintDocument, which allows you to print any DocumentPaginator (e.g. FlowDocument or XpsDocument).

Troubleshooting tips

More resources on Windows Presentation Foundation 

Book excerpt: Windows Presentation Foundation and custom controls 

Book excerpt: What's new in Windows Presentation Foundation

Your element, canvas, grid or other object may print out very small. I explain why this happens and demonstrate how you can use a Transform before printing to correct.

Also, when printing a multiple-page document from a FlowDocumentPageViewer or FlowDocumentReader, the pages may scale to the same size as the document being shown on the screen. Here's how to change the height and width of the document before printing.

If you enjoyed this article, be sure to visit the WPF Reflections blog for more Windows Presentation Foundation techniques.

   GOT DEVELOPER QUESTIONS? YOUR PEERS HAVE ANSWERS
Your fellow developers have faced the same or similar problems.
So ask your own question on the IT Knowledge Exchange community.


This was first published in June 2008

Dig deeper on .NET Framework 3.0 design and architecture tools

0 comments

Oldest 

Forgot Password?

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

Your password has been sent to:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close