Printing in Windows Presentation Foundation

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.

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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.