views:

1849

answers:

3

We have an ASP.NET C# web application with a "printer friendly" link. Is there a way to programmatically set the orientation to landscape, so the user can just press the print button?

+3  A: 

The short answer is "No." It is a deliberate limitation of browsers that the page itself cannot override the user's print settings. This is to prevent abuse I would imagine and causes all sorts of headaches.

One possible work around would be to output your page as a PDF and present that. You can control the print settings for a PDF page.

Rob Allen
+1 for the pdf methode. I had to use this at work and every body had acrobat reader...
Polo
+5  A: 

This is something that would have to be done on the client side (using JavaScript/CSS).

Unfortunately, JavaScript does not have the ability to make this change.

CSS does have a means of specifying landscape printing via the @page directive:

@page {
    size: landscape;
}

However, very few browsers support it.

In other words... You can't.

AaronSieb
Excellent point about the print CSS rules. +1
Randolpho
+1  A: 

No, there is no programmatic way to set orientation. It's entirely handled by the browser.

The best you can do is say "we recommend you print the page with Landscape (or Portrait)" and hope the user knows how to do it themselves.

Randolpho