Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set print page orientation to landscape

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?

like image 703
Bobby Ketchum Avatar asked Dec 13 '22 03:12

Bobby Ketchum


2 Answers

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;
}

CSS Paged Media is well supported by Chrome v15+ and Opera v15+, is partially supported by Firefox v19+, IE8+ and all versions of Edge. However it is not supported by Safari at all

https://caniuse.com/#feat=css-paged-media

like image 177
AaronSieb Avatar answered Jan 12 '23 09:01

AaronSieb


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.

like image 43
Rob Allen Avatar answered Jan 12 '23 07:01

Rob Allen