Given the following html code:
<html>
<style>
div.container > table {
border-collapse: collapse;
}
div.container > table > tbody > tr > td {
border: 1pt solid;
}
</style>
<body>
<div class="container">
<p>Hello</p>
<table>
<tbody>
<tr>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
</tr>
</tbody>
</table>
<p>Hi</p>
</div>
</body>
</html>
I want to print to A4 portrait orientation in the following way:
I tried adding the following style:
@media print {
@page {
size: a4 portrait;
}
div.container > table {
break-before: page;
break-after: page;
transform: rotate(-90deg);
}
}
The problem are that:
How can I achieve my objective?
Requirements:
Related question is no good because (1) the first solution prints everything in landscape mode, not just the table (2) the second solution has the same problems of the solution I propose.
EDIT:
Tried this but didn't work:
@media print {
@page general{
size: a4 portrait;
}
@page rotated {
size: a4 landscape;
}
div.container {
page: general;
}
div.container > table {
break-before: page;
break-after: page;
page: rotated;
}
}
Try this. Click on the page (on the text "hello" for example) to open the print preview.
document.body.addEventListener("click", ()=>{
window.print()
});
table
{
transform: rotate(90deg) translate(0%, -100vw);
transform-origin: left top;
display: block;
position: relative;
break-before: page;
break-after: page;
margin: 0px -20px;
}
<html>
<style>
div.container > table {
border-collapse: collapse;
}
div.container > table > tbody > tr > td {
border: 1pt solid;
}
</style>
<body>
<div class="container">
<p>Hello</p>
<table>
<tbody>
<tr>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
<td>Lorem ipsum</td>
</tr>
</tbody>
</table>
<p>Hi</p>
</div>
</body>
</html>