Possible to force printer setup (paper size) in javascript?

后端 未结 2 1925
南旧
南旧 2020-11-30 05:19

I have a need to print pages from a web app on to 8\" x 4\" index cards. IE doesn\'t save print settings from one print to the next, so is there a way to programmatically fo

相关标签:
2条回答
  • 2020-11-30 05:34

    Look at this CSS3 examples from http://www.w3.org/TR/css3-page/#size:

    /* style sheet for "A4" printing */
    @media print and (width: 21cm) and (height: 29.7cm) {
         @page {
            margin: 3cm;
         }
    }
    
    /* style sheet for "letter" printing */
    @media print and (width: 8.5in) and (height: 11in) {
        @page {
            margin: 1in;
        }
    }
    
    /* A4 Landscape*/
    @page {
        size: A4 landscape;
        margin: 10%;
    }
    
    0 讨论(0)
  • 2020-11-30 05:46

    You can do this in CSS using the @media print directive, no js required. You'll have to calculate what sizes relate to a 4x8 index card and do all the positioning yourself, but it will work. Also, since this is CSS2 it won't work in IE6. (see Joel's comments)

    @media print {
      body {
        width: /*width of index card*/
        height: /*height of index card*/
      }
      /* etc */
    }
    
    0 讨论(0)
提交回复
热议问题