Various WPF applications of mine display FlowDocument's. I'm able to print them, using the approach described in the answer to Printing a WPF FlowDocument.
Now I'd like to add a "print preview" capability. In the normal case, I am printing the FlowDocument that is displayed in the Window, and so I wouldn't need a Print Preview then. But in some cases the FlowDocument to print is constructed on-the-fly in memory. And in these cases I'd like to display it before printing.
Now, I can certainly pop a new window and display the FlowDocument, but
I want the preview to really feel like it is part of the printing operation, and not just another Window in the app.
I don't want a normal FlowDocument in a FlowDocumentScrollViewer. Rather than being "any size" it needs to be constrained to the size of the paper, a specific HxW ratio, and paginated.
Suggestions?
should I just use a standard Window, and in that case, how to I ensure the FlowDocument is at the proper ratio?
is there a more "integrated" way to do the preview within the scope of the PrintDialog UI that is part of Windows?
Thanks
The "FlowDocumentPageViewer" control is the basis for the "preview" control used in one of our projects. Here is the XAML of the "DocumentPreviewer" control (apologies for the length -- XAML is not succinct):
Where you might put such a control is up to you (and your app) of course, but our app has a similar behavior to the typical Office app where you can either print directly or preview (which shows the above interface) and print from there.
Taking the hint from the comment added to my question, I did this:
What it does: it actually prints the content of a visual into an XPS document. Then it loads the "printed" XPS document and displays it in a very simple XAML file that is stored as a string, rather than as a separate module, and loaded dynamically at runtime. The resulting Window has the DocumentViewer buttons: print, adjust-to-max-page-width, and so on.
I also added some code to hide the Search box. See this answer to WPF: How can I remove the searchbox in a DocumentViewer? for how I did that.
The effect is like this:
alt text http://i48.tinypic.com/2hzkfat.jpg
The XpsDocument can be found in the ReachFramework dll and the XpsDocumentWriter can be found in the System.Printing dll both of which must be added as references to the project