Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Window.print() paper orientation

I want to change paper mode (orientation) on the window print. I want to change it programatically but i could not find anything.

window.print()

But i do not know , how can i do it.

@media print{@page {size: landscape}}

I dont need it.

    function printWindow()
    {
        window.print({
        /*
        some code here?
        */
        });
}
like image 746
Somomo1q Avatar asked Aug 18 '16 19:08

Somomo1q


People also ask

How do I change the paper orientation on my printer?

Change mode in printer settingsOpen the Control Panel and then the Devices and Printers option. Find your printer in the Devices and Printers window and right-click the icon with your mouse. In the menu that appears, select Printing Preferences and find the option for Orientation in the preferences window.

Why is my paper printing sideways?

Although the printer might be correctly configured to print in Portrait mode, the program itself might be configured to print in Landscape mode. These settings are typically adjusted by locating a Page Setup or Page Layout menu and then looking for Orientation.


3 Answers

You need to inject style to your document.

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/

like image 86
Denis Matafonov Avatar answered Sep 20 '22 02:09

Denis Matafonov


the simplest way to change page print orientation is by using following CSS

@page {     size: 25cm 35.7cm;     margin: 5mm 5mm 5mm 5mm; /* change the margins as you want them to be. */ } 
like image 29
shyamm Avatar answered Sep 22 '22 02:09

shyamm


This one worked for me, was generating an A1 sales summary sheet

var head = '<html><head>' 
      + $("head").html() 
      + ' <style>body{background-color:white !important;}@page { size: 84.1cm 59.4cm;margin: 1cm 1cm 1cm 1cm; }</style></head>';

//Additional code here......

Just inject the current head css so that your data does not lose the previous styling

like image 38
NINSIIMA WILBER Avatar answered Sep 20 '22 02:09

NINSIIMA WILBER