Posted by: MarkWPF
printing, Windows Computing, WPF, XAML
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;
Of course, you will need to remember to save the FlowDocument’s height and width, then re-apply after you have printed the document.