I do set to landscape the size property of a CSS file to print pages in landscape
@page {
margin: 0.1cm;
size: landscape;
orientation: landscape;
size: A4;
Some pages are printed into portrait orientation, some in landscape orientation.
How can i detect and force the pages to be printed in landscape using CSS ?
screen. orientation. lock('landscape'); Will force it to change to and stay in landscape mode.
portrait. The viewport is in a portrait orientation, i.e., the height is greater than or equal to the width. landscape. The viewport is in a landscape orientation, i.e., the width is greater than the height.
Whether you are holding your device upwards or sideways, swipe down from the top of the screen. Tap the Auto rotate icon to lock your device in your desired position.
1 Swipe down the screen to access your Quick Settings and tap on Auto Rotate, Portrait or Landscape to change your screen rotation settings. 2 By selecting Auto Rotate,you will easily be able to switch between Portrait and Landscape mode.
The CSS you provided has problems:
}
),size
with A4
orientation
seems to exist for media queries, but not as an attribute (source). Hence you can check the orientation, but not set it.I tried
@page {
size: A4 landscape;
}
in Chrome 60 on Linux and it worked. Seems not to work in Firefox, though.
You could set the width
and height
of the <body>
to whatever you need (only for printing by using the media query) just like paper.css does.
You could add
body {
transform: rotate(-90deg);
}
Seems to be safe to use.
The problem is first you write size: landscape;
but than you write size: A4;
If not provided domPDF is rendering like default portrait, and it overwrites the landscape.
set the second parameter landscape and will work out.
size: A4 landscape;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With