Set Printing Preferences from JS

前端 未结 4 2035
南旧
南旧 2020-12-15 18:24

So... from what I can find on the Google, I can\'t find a way to use Javascript to set my printing preferences (read: margins, orientations, footer, etc).

I am abou

4条回答
  •  佛祖请我去吃肉
    2020-12-15 19:21

    You can set page orientation and margin with CSS:

    @page {
       size: landscape;
       margin: 10%
    }
    

    You can also set a footer at the bottom of each page by using the element.

    EDIT: As pointed out by Beejamin, this is a half-way house. You can't really change printer preferences (those that appear in the Print Dialog when clicking Print). Also, IE is severely lacking in support for @page selector, (had a look around to see if IE9 supported it and couldn't find anything). As an alternative you could always try applying it to the body in your print stylesheet.

    body {
       size: landscape;
       margin: 10%
    }
    

    Although off my head I'm not sure how effective this is.

提交回复
热议问题