12

In our application we enable users to print pages. We do this by supplying a button which when click calls the window.print() function.
Some of the pages would look better if they were printed in landscape mode rather than portrait. Is there a way to control the page layout from JavaScript?

Update: Following the advice given here I looked for "css landscape" in google, and found the following article that showed ways of css-ly defining landscape:

Lea Cohen
  • 7,990
  • 18
  • 73
  • 99

4 Answers4

9

You should use a print stylesheet.

<link rel="stylesheet" href="print.css" type="text/css" media="print" />

More info...

How to print only parts of a page?

Edit: to coerce landscape orientation, apparently the standard is size: landscape, but I have no idea how well that's supported across browsers.

Community
  • 1
  • 1
eyelidlessness
  • 62,413
  • 11
  • 90
  • 94
  • Thanks for the update. According to the article I linked to in my question, that's supported in FireFox and Opera, but not in IE – Lea Cohen Oct 27 '08 at 07:28
2

Do it with CSS by including a print stylesheet thusly:

<style type="text/css" media="print">@import url("/inc/web.print.css");</style>
da5id
  • 9,100
  • 9
  • 39
  • 53
2

I think your question is not so much about using CSS to define print styles, but to force the print as landscape rather than portrait?

CSS 2 defined 'size', but I don't think this is widly supported: http://www.w3schools.com/css/css_ref_print.asp

CSS 3 has better print control, but again not widly supported.

Ady
  • 4,736
  • 2
  • 22
  • 20
1

Unfortunately, this is still not possible cross-browser. For Internet Explorer, there is an ActiveX control that does it.

Otherwise your best bet might be to offer the option of a PDF version for printing.

Lee Kowalkowski
  • 11,591
  • 3
  • 40
  • 46