tags:

views:

2222

answers:

6

I have a HTML report, which needs to be printed landscape because of the many columns. It there a way to do this, without the user having to change the document settings?

And what are the options amongst browsers.

A: 

You can also use the non-standard IE-only css attribute writing-mode

div.page    { 
   writing-mode: tb-rl;
}
Anonymous
This does reorient the page content but doesn't really change the page layout to landscape. I.e. the headers and footers will still be added as if the page was portrait.
Daniel Ballinger
+4  A: 

You might be able to use the CSS 2 @page rule which allows you to set the 'size' property to landscape.

Ian Oxley
A: 

Try to add this your CSS:

@Page {
  size: landscape;
}
gizmo
Did this work for you with any of the browsers? With IE8 and Firefox3.5 it didn't seem to make any difference to the print preview.
Daniel Ballinger
The print preview does not follow all the CSS properties, unfortunately. But this should works in all the current browsers.
gizmo
Thanks for following up on this. It doesn't seem to work for me with actual printing either. Have I missed something? My test file is as follows: (I've had to truncate the paragraph content to fit in the comment box)<html><head> <title>Landscape testing Page</title> <style> @Page { size: landscape; } </style></head><body> <p> Lorem ipsum dolor sit amet, ... </p></body></html>
Daniel Ballinger
+9  A: 

In your CSS you can set the page property as shown below. However this is not supported and does not work in IE7 or earlier.

@media print{@page {size: landscape}}

It may seem to work in IE7 but this is because IE7 will remember the users last selection of landscape or portrait in print preview (only the browser is re-started).

This article does have some suggested work arounds using JavaScript or ActiveX that send keys to the users browser although it they are not ideal and rely on changing the browsers security settings.

Alternately you could rotate the content rather than the page orientation. This can be done by creating a style and applying it to the body that includes these two lines but this also has draw backs creating many alignment and layout issues.

<style type="text/css" media="print">
    .page
    {
     -webkit-transform: rotate(-90deg); -moz-transform:rotate(-90deg);
     filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
    }
</style>

The final alternative I have found is to create a landscape version in a PDF. You can point to so when the user selects print it prints the PDF. However I could not get this to auto print work in IE7.

<link media="print" rel="Alternate" href="print.pdf">

In conclusion in newer browsers it is relativity easy using the @page size option however in older browsers there is no sure way and it would depend on your content and environment. This maybe why Google Documents creates a PDF when print is selected and then allows the user to open and print that.

John
odd that it says 'size' can be landscape, when that's actually an 'orientation'.
Magnus Smith
A: 

I tried to solve this problem once, but all my research led me towards ActiveX controls/plug-ins. There is no trick that the browsers (3 years ago anyway) permitted to change any print settings (number of copies, paper size).

I put my efforts into warning the user carefully that they needed to select "landscape" when the browsers print dialog appeared. I also created a "print preview" page, which worked much better than IE6's did! Our application had very wide tables of data in some reports, and the print preview made it clear to the users when the table would spill off the right-edge of the paper (since IE6 couldnt cope with printing on 2 sheets either).

And yes, people are still using IE6 even now.

Magnus Smith
A: 

.landscape { width: 100%; height: 100%; margin: 0% 0% 0% 0%; filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=1); }

If you want this style to be applied to a table then create one div tag with this style class and add the table tag within this div tag and close the div tag at the end.

This table only will print in landscape and all other pages will print in portrait mode only. But the problem is if the table size is more than the page width then we may loose some of the rows and some times headers also are missed. Becarefull. Have a gud day. Thankyou, Naveen Mettapally.

Naveen Mettapally