WPF Reflections

May 14 2008   9:04AM GMT

WPF Problems printing documents

Mark Shurmer Profile: MarkWPF

Do you have problems printing documents in WPF?

My problem manifested itself when I tried to print a document from a FlowDocumentPageViewer (though the same is true from a FlowDocumentReader).
The problem I was getting was that if I had multiple pages, they would all be scaled and fitted onto the same size of printed page as on the screen.

How do you get around this?
Well the problem lies in the fact that the document is being shown on the screen which has a different size to the printed page.
Realising that, the solution itself is simple – change the height and width of the document before printing it, like:

Assuming docRdr is a FlowDocumentPageViewer and prtDlg is a PrintDialog:

FlowDocument doc = docRdr.Document;
doc.PageHeight  = prtDlg.PrintableAreaHeight;
doc.PageWidth   = prtDlg.PrintableAreaWidth;
prtDlg.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, “Statement”);

Of course, you will need to remember to save the FlowDocument’s height and width, then re-apply after you have printed the document.

 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: