Landscape printing from HTML

前端 未结 16 1814
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 06:31

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?

相关标签:
16条回答
  • 2020-11-22 07:04

    Try to add this your CSS:

    @page {
      size: landscape;
    }
    
    0 讨论(0)
  • 2020-11-22 07:06

    My solution:

    <style type="text/css" media="print">
        @page { 
            size: landscape;
        }
        body { 
            writing-mode: tb-rl;
        }
    </style>
    

    This works in IE, Firefox and Chrome

    0 讨论(0)
  • 2020-11-22 07:06

    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.

    0 讨论(0)
  • 2020-11-22 07:10

    This also worked for me:

    @media print and (orientation:landscape) { … }
    
    0 讨论(0)
  • 2020-11-22 07:12
    <style type="text/css" media="print">
    .landscape { 
        width: 100%; 
        height: 100%; 
        margin: 0% 0% 0% 0%; filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=1); 
    } 
    </style>
    

    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 will only 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 sometimes headers also are missed. Be careful.

    Have a good day.

    Thank you, Naveen Mettapally.

    0 讨论(0)
  • 2020-11-22 07:13

    Quoted from CSS-Discuss Wiki

    The @page rule has been cut down in scope from CSS2 to CSS2.1. The full CSS2 @page rule was reportedly implemented only in Opera (and buggily even then). My own testing shows that IE and Firefox don't support @page at all. According to the now-obsolescent CSS2 spec section 13.2.2 it is possible to override the user's setting of orientation and (for example) force printing in Landscape but the relevant "size" property has been dropped from CSS2.1, consistent with the fact that no current browser supports it. It has been reinstated in the CSS3 Paged Media module but note that this is only a Working Draft (as at July 2009).

    Conclusion: forget about @page for the present. If you feel your document needs to be printed in Landscape orientation, ask yourself if you can instead make your design more fluid. If you really can't (perhaps because the document contains data tables with many columns, for example), you will need to advise the user to set the orientation to Landscape and perhaps outline how to do it in the most common browsers. Of course, some browsers have a print fit-to-width (shrink-to-fit) feature (e.g. Opera, Firefox, IE7) but it's inadvisable to rely on users having this facility or having it switched on.

    0 讨论(0)
提交回复
热议问题