WPF Problems printing documents
Posted by: Mark Shurmer
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.



You must be logged-in to post a comment. Log-in/Register