|
-
Jun 3rd, 2010, 03:59 AM
#1
Print Preview with WPF
I'm trying to print in WPF with the option to give a print preview. It looks like this was easy using the older .NET Windows Forms APIs, but there's not a whole lot I've been able to find on printing in WPF.
My first question is this: does anyone know a good WPF printing tutorial which includes how to add a print preview?
I've been able to find two main methods for printing: using either a PrintDialog's PrintVisual or PrintDocument method. I'd like to create the Visual or DocumentPaginator object for use with these and simply pass the object off to some routine which displays a preview. Creating these objects is not a problem. Right now I'm making a preview by creating a window backed by the following (very simple) XAML:
XML Code:
<Window x:Class="MyProgram.winPrintPreview" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowState="Maximized" Title="Print Preview"> <Grid> <DocumentViewer Name="Viewer" /> </Grid> </Window>
The code behind basically creates a dummy XpsDocument initialized from a blank file. It then creates an XpsDocumentWriter which Write()'s my Visual or DocumentPaginator object to the XpsDocument (currently I'm only testing with Visual objects). Finally, the XpsDocument is displayed by setting the DocumentViewer's Document property. All of this is currently working.
Sometimes I need to print in Landscape orientation, but I can't figure out how to tell the DocumentViewer that. Right now, the DocumentViewer gives me a Portrait view no matter what. I've hunted through the properties of the XpsDocument but haven't been able to find a way to set the page orientation there. I've done the same with the DocumentViewer. If it helps, I don't think I'll ever need different pages to have different orientations. It should be either all Portrait or all Landscape.
My second question then is this: how can I make the DocumentViewer use Landscape orientation?
I have a workaround available. I could make a custom window provide print previews by just displaying the Visual for each page directly. It seems like a waste of my time to have to implement my own preview, though, especially when something is already so close to working. The DocumentViewer has more features than I would bother putting in my own preview, too.
Any help is greatly appreciated .
P.S. I'm actually developing in C#, but this forum seems to get much more traffic. I would have included slightly more code except it's in C#. Also, I've only been using .NET for around two weeks, so feel free to explain things you might find simple.
Last edited by jemidiah; Jun 3rd, 2010 at 04:04 AM.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Jun 3rd, 2010, 05:39 AM
#2
Re: Print Preview with WPF
Please post in the most appropriate forum, not the one that gets the most traffic. This site has a WPF forum so I've asked the mods to move this thread there.
-
Jun 3rd, 2010, 05:55 AM
#3
Re: Print Preview with WPF
And so we have, thanks.
Moved to WPF, WCF, WF
-
Jun 3rd, 2010, 07:58 PM
#4
Re: Print Preview with WPF
Alrighty. I had searched the WPF forum for "print" and "printing", and none of the results actually discuss printing in WPF. I figure there's small chance of getting an answer to a specific question like this when the general version hasn't been answered in this forum, especially with how relatively little traffic this forum gets. I understand organization is nice. Ah well.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|