Is it possible to force a printer (paper size) in javascript?

I need to print pages from a web application on 8 "x 4" index cards. IE doesn't save print options from one print to the next, so is there a way to programmatically force the print?

+7
javascript printing
source share
2 answers

Sala.

Check out the 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%; } 
+4
source share

You can do this in CSS using the @media print directive, no js is required. You will need to calculate what sizes apply to the 4x8 index card and do all the positioning yourself, but it will work. Also, since this is CSS2, it will not work in IE6. (see Joel comments)

 @media print { body { width: /*width of index card*/ height: /*height of index card*/ } /* etc */ } 
+11
source share

All Articles