Print in Landscape format

127,383

you cannot set this in javascript, you have to do this with html/css:

<style type="text/css" media="print">
  @page { size: landscape; }
</style>

EDIT: See this Question and the accepted answer for more information on browser support: Is @Page { size:landscape} obsolete?

Share:
127,383
RRMN
Author by

RRMN

Updated on July 08, 2022

Comments

  • RRMN
    RRMN almost 2 years

    Possible Duplicate:
    Landscape printing from HTML

    I am using below code to show print window on button click:

    function print_onclick() {
        window.print();
        return false;
    }
    

    I want the page to be printed in Landscape format. Is there any property I can add in above code to make it work ?

    Additional Info: Since my page width is 1280 px, when I print it on A4 paper with portrait orientation, the font becomes too small. I want to print only 2 lines. If not landscape, is there a way I can fix the font size of those table cell/divs while printing ?

  • RRMN
    RRMN over 11 years
    This doesnot seem to work for IE7.
  • hereandnow78
    hereandnow78 over 11 years
    do you really have to support ie7? if it is not a must, please do not do not care about ie7
  • farid bekran
    farid bekran about 11 years
    very very useful. thanks.
  • Jared
    Jared about 11 years
    It's a must for some people hereannow78. I'm on client site and that's their primary browser.
  • Dave Hollingworth
    Dave Hollingworth over 10 years
    This doesn't seem to work in Firefox (version 24 at the moment), but it does work in Chrome (version 30). Generating a PDF is an alternative that would work in all browsers (although more work / more processing required on the server etc.)
  • Jeff
    Jeff almost 10 years
    Can second the fact that works for Chrome 36 but not Firefox 31.
  • Remya R
    Remya R about 8 years
    not working in firefox
  • James Haug
    James Haug over 7 years
    Does not work in Chrome 54.0.2840.99 m
  • Abeer Sul
    Abeer Sul over 7 years
    Is this supposed to work in IE11?? it didn't work with me. The default print orientation is always portrait, I have to manually change it from settings
  • Ryan Smith
    Ryan Smith over 3 years
    developer.mozilla.org/en-US/docs/Web/CSS/@page/… This still doesn't seem to be widely supported (No Firefox, No IE, No Safari) even in 2021.