2016-08-18 24 views
10

Pencere baskısında kağıt modunu (yönünü) değiştirmek istiyorum. Programlı olarak değiştirmek istiyorum ama hiçbir şey bulamadım.Change Window.print() kağıt yönü

window.print()

Ama bilmiyorum, ben bunu nasıl yapabilirim.

Buna ihtiyacım yok.

function printWindow() 
    { 
     window.print({ 
     /* 
     some code here? 
     */ 
     }); 
} 
+3

kullanmaktır ama bunun Yapabileceğin bir şey olduğunu sanmıyorum. Kağıt boyutu ve yönlendirmesi kullanıcıya kalmış. – Brad

cevap

12

Belgenize stil enjekte etmeniz gerekir.

var css = '@page { size: landscape; }', 
    head = document.head || document.getElementsByTagName('head')[0], 
    style = document.createElement('style'); 

style.type = 'text/css'; 
style.media = 'print'; 

if (style.styleSheet){ 
    style.styleSheet.cssText = css; 
} else { 
    style.appendChild(document.createTextNode(css)); 
} 

head.appendChild(style); 

window.print(); 

//don't forget to find and remove style if you don't want all you documents stay in landscape 

https://jsfiddle.net/vc4jjhpn/

+0

Ve Bitti. Teşekkür ederim ben var :) –

1

sayfa yazdırma yönünü değiştirmek için basit yolu yanlış olabilir aşağıdaki CSS

@page { 
    size: 25cm 35.7cm; 
    margin: 5mm 5mm 5mm 5mm; /* change the margins as you want them to be. */ 
}