WPF Reflections

Apr 11 2008   2:48PM GMT

WPF Printing using PrintVisual



Posted by: Mark Shurmer
WPF, XAML, printing

To do a simple print in WPF, you can do the following:

PrintDialog prtDlg = new PrintDialog();
if(prtDlg.ShowDialog() == true)
{
prtDlg.PrintVisual(element, “A simple drawing”);
}

This will throw up the XP or Vista print dialog, and then print the element specified, no problems at all.
Actually there are a couple of problems:

  1. The element is always lined up in the top left of the printed page
  2. If you haven’t specified any margin, the element might get cut off
  3. There’s no pagination
  4. It uses the same device independent system for printing as showing on the screen ,1:96, so an element 96 pixels wide will appear 1 inch wide on the printed paper

Comment on this Post


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