views:

919

answers:

3

Is there a way to set the Default Layout Orientation when printing XPSs using the WPF XPS Viewer? My fixed document XPS has its page orientation set to Landscape, the Page Media Size has a width that is longer that its height and it displays correctly in the Viewer as Landscape. Its just that when you hit the print button the Print Dialog preferences are defaulted to Portrait and it prints as such. I'd rather not have to alter the users default print settings I'd much prefer it if the XPS Viewer would print the XPS as it was designed to be printed.

A: 

This is not really a problem with MXDW but one with the way drivers work on Windows. The user choice(s) is/are saved for a particular session. This means that you can reuse firs-print settings when printing between the first print and quitting the application. Most printers behave this way, until unless one comes up with a way to save this information somewhere and let the user re-use it across sessions.

So, I tried hacking the GPD file (where printing information for a printer is typically stored). The orientation has two possible values: PORTRAIT and LANDSCAPE_CC270 with the default being set to PORTRAIT. See below:

*%************************************************************************** *% Orientation *%************************************************************************** *Feature: Orientation { *rcNameID: =ORIENTATION_DISPLAY *DefaultOption: PORTRAIT

*Option: PORTRAIT
{
    *rcNameID: =PORTRAIT_DISPLAY
}

*Option: LANDSCAPE_CC270
{
    *rcNameID: =LANDSCAPE_DISPLAY
}

}

Now, if I were to change swap the default value to LANDSCAPE_CC270, the printing preferences stop coming up (and any print would fail). In fact, it appears, that specifying any other value keeps the default to PORTRAIT. Definitely, MS is doing some sort of check to prevent us from hacking this driver. Looks like MS doesn't want anyone to tamper with its settings :(

But you could try flirting with the GPD values a bit more and see if something of your liking comes up. Will keep hacking a bit more.

Caveat: GPD files shouldn't be tampered with if you don't know what you are doing. If you still want to go ahead make a backup!

Hint: They are stored in %WINDOWS%system32\spool\drivers\w32x86\3 folder.

dirkgently
A: 

I answered this related question, hope that may help?

mcw0933
A: 

I believe the correct way to do this when creating a FixedDocument, is set the RenderTransform = RotateTransform(90) on the page content when the dimensions are higher than they are wide. Example:

var visualContent = new Image
            {
                Source = image,
                Stretch = Stretch.Uniform
            };
visualContent.RenderTransformOrigin = new Point(0.5, 0.5);    
visualContent.RenderTransform = new RotateTransform(90);
FixedPage fixedPage = new FixedPage();
fixedPage.Children.Add(visualContent);
var pageContent = new PageContent
{
    Child = fixedPage
};

Not sure if that helps with a pre-existing XPS document however.

Flatliner DOA