I am trying to create a book using webdesign. To do so, I need an A4 page with a box-border around the page. If the border is achieved along with specified page breaks, achieving rest of the design should be relatively is easy.
The problem now is that the borders from succeeding page is creeping slightly into the previous page.
page-break-after: always;
is also not working for .page
My Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>JSS Report</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="main.js"></script>
<style>
@media print {
@page {
size: A4;
width: 210mm;
height: 297mm;
margin: 1cm;
margin-left: 1.5cm;
box-sizing: border-box;
border-style: solid;
border-color: green;
border-width: medium;
}
body {
display: flex;
flex-direction: column;
align-content: center;
justify-content: center;
}
.page {
display: flex;
width: calc(210mm - 2.5cm);
height: calc(297mm - 2cm);
flex-direction: column;
align-content: center;
justify-content: center;
box-sizing: border-box;
box-shadow: inset 5px 5px red, inset -5px -5px red;
page-break-after: always;
/*Not Working*/
}
}
</style>
</head>
<body>
<div class="page">
Hello Page 1
</div>
<div class="page">
Hello Page 2
</div>
<div class="page">
Hello Page 3
</div>
<div class="page">
Hello Page 4
</div>
<div class="page">
Hello Page 5
</div>
<div class="page">
Hello Page 6
</div>
<div class="page">
Hello Page 7
</div>
<div class="page">
Hello Page 8
</div>
</body>
</html>
The generated PDF file has the size => 8.28in x 11.69in
while A4 sheet should have the size => 8.27in x 11.69in
I think this is the reason why the borders from succeeding page is creeping slightly into the previous page.
What I've tried:
border-style: solid;border-color: red;
box-sizing: border-box;
I resist the use PDF generator API's or Libraries. Do I really need them for making a simple page with border & page-breaks?