WPF Reflections

Apr 11 2008   2:48PM GMT

WPF Printing using PrintVisual

Mark Shurmer Profile: MarkWPF

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

1  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.

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
  • Siten0308
    Hello, Thank you for the information, i am doing a practice examle with your example, its showing up this weird error message do you know? here is the code below including the error message, thank you private void btnprint_Click(object sender, RoutedEventArgs e) { System.Windows.Controls.PrintDialog prtDlg = new System.Windows.Controls.PrintDialog(); if(prtDlg.ShowDialog() == true) { prtDlg.PrintVisual(bitmap, desc); } } error message: the best overload method match for system.windows.controls.printdialog.printvisual(system.windows.media.visual, string); has some invalid arguments argument 1: cannot convert from system.window.media.imaging.bitmapimage to system.windows.media.visual. PLEASE HELP : (
    0 pointsBadges:
    report

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: