tags:

views:

158

answers:

2

Hi. I am able to print the current Window using the following code:

        PrintDialog printDialog = new PrintDialog();
        if (printDialog.ShowDialog().GetValueOrDefault(false))
        {
            printDialog.PrintVisual(this, this.Title); 
        }

However if the Window does not fit the page it get truncated. How do I make the Window fit the Page ?
I guess I need to make a graphics element first and check if this graphics fits the page, but I have found nothing so far.

A: 

If you give your window a fixed Height and Width you can adjust that to fit on the printing paper. If I am not mistaken WPF uses 96 pixels per inch.

Dabblernl
Would't that resize the currently displayed Window, too ?I'll give it a try..
Nils
A: 

There is one solution out there that lots of people are reposting as their own. It can be found here:

http://www.a2zdotnet.com/View.aspx?id=66

The problem w/ that is that it does resize your UI. So this next link takes the previous solution and resizes back to the original size when it's done. This does work, although I can't help but to think there's likely a more elegant solution out there somewhere:

http://www.slickthought.net/post/2009/05/26/Visual-Tree-Printing-in-WPF-Applications.aspx

Paul Prewett
I did not find a more elegant solution...
Nils